The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Flash
  • Flex
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Flash
 Flex

  • wraevn Author 
    • 2731 
    • 0 
    • 3 
    Text as Mask ... not working
    Isocase

    Last reply Jan 16 2009, 05:01 PM

    by Isocase

    Posted: Jan 16 2009, 01:49 PM

    by wraevn

     

I’m trying to get the effect of a gradient fill for text. I figured - draw a gradient rect, then mask it w/ text.

I’m having a difficult time masking a UIComponent (could be anything really) with a Text component. The following works great in Flash (provided you embed the font of course).

[as]var tf:TextField = new TextField();
tf.text = “GRADIENT TEXT”;
tf.embedFonts = true;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.setTextFormat( new TextFormat( “Arial”, 20, 0x000000 ) );

var rect:Sprite = new Sprite();
var matrix:Matrix = new Matrix();
matrix.createGradientBox( 100, 20, Math.PI / 2 );
rect.graphics.beginGradientFill( GradientType.LINEAR, [ 0x000000, 0xffffff, 0x000000 ], [1,1,1], [0, 130, 255], matrix );
rect.graphics.drawRect( 0, 0, tf.width, tf.height );
rect.graphics.endFill();

rect.mask = tf;

addChild( rect );
addChild( tf );[/as]

Here is what I was trying to do in Flex - w/ no success:

[as]
var textMask:Text = new Text();
textMask.text = “GRADIENT TEXT”;
textMask.setStyle( “color”, 0x000000 );
textMask.setStyle( “fontFamily”, “Arial” );
textMask.setStyle( “fontWeight”, “Bold” );
textMask.setStyle( “fontSize”, 15 );
textMask.selectable = false;

var gradientRect:UIComponent = new UIComponent();
gradientRect.cacheAsBitmap = true;

var g:Graphics = gradientRect.graphics;
var matrix:Matrix = new Matrix();
matrix.createGradientBox( 100, 20, Math.PI / 2 );

g.beginGradientFill( GradientType.LINEAR, [ 0x000000, 0xffffff, 0x000000 ], [1,1,1], [0, 130, 255], matrix );
g.drawRect( textMask.x, textMask.y, this.width, this.height );
g.endFill();

gradientRect.mask = textMask;

addChild( gradientRect );
[/as]

I first checked to make sure that the gradient was getting drawn and that its width and height were correct. I also checked to ensure that the text was getting placed correctly.

I need to double-check I guess that the embedded font Arial is in fact getting used - it is elsewhere in the app.

Any help here will be GREATLY appreciated.

Thanks,

B

  3 REPLIES
 
Isocase
1  
Isocase

Here you go. I embed the Arial font into my library and just took a bitmapdata screen shot of it. Not sure if there is a cleaner way but this does work

var arial:Font = new ArialFont();

var 
format:TextFormat = new TextFormat();
format.color = 0x000000;
format.font = arial.fontName;
format.size = 20;

var 
field:TextField = new TextField();
field.antiAliasType = AntiAliasType.ADVANCED;
field.autoSize = TextFieldAutoSize.LEFT;
field.embedFonts = true;
field.defaultTextFormat = format;
field.selectable = false;
field.text = "GRADIENT TEXT";
addChild(field);

var 
bitmapdata:BitmapData = new BitmapData(field.width, field.height, true, 0);
var 
matrix:Matrix = new Matrix();
bitmapdata.draw(field, matrix);

var 
bitmap:Bitmap = new Bitmap(bitmapdata, "auto", true);
bitmap.cacheAsBitmap = true;
bitmap.x = Math.round((stage.stageWidth-bitmap.width)*.5);
bitmap.y = Math.round((stage.stageHeight-bitmap.height)*.5);
addChild(bitmap);
removeChild(field);

var 
gradientmatrix:Matrix = new Matrix();
gradientmatrix.createGradientBox(bitmap.width, bitmap.height, Math.PI/2);

var 
shape:Shape = new Shape();
shape.graphics.beginGradientFill(GradientType.LINEAR, [0x000000, 0xffffff, 0x000000], [1,1,1], [0, 130, 255], gradientmatrix);
shape.graphics.drawRect(0, 0, bitmap.width, bitmap.height);
shape.graphics.endFill();
shape.cacheAsBitmap = true;
shape.x = Math.round((stage.stageWidth-bitmap.width)*.5);
shape.y = Math.round((stage.stageHeight-bitmap.height)*.5);

shape.mask = bitmap;
addChild(shape); 
  • 16 January 2009 04:28 PM
  •  
wraevn Author 
2  
wraevn

Okay - so, what I have up above also works in Flash (and you don’t need to take a bitmap snapshot).

But I guess what you’re saying is try this in Flex?

  • 16 January 2009 04:51 PM
  •  
Isocase
3  
Isocase

Yeah try that out in Flex. My above was is just another way to do it you know what I mean. Also try embedding a different font than Arial. Maybe a non-standard font or something like that.

  • 16 January 2009 05:01 PM
  •  
  •   Log in or join for free to make a comment.
 
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 779  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,728  Assets
  • Profiles 282,751  Members
  • Topics 93,776  Topics
  • Blog 4  Blog
  • Facebook 1,679  Facebook
  • Twitter 1,163  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Sat, February 11, 2012 - 19:59:23