Using actionscript 3 to Mask text thats in a movieclip
I am dynamicly adding xml data into three text fields buy looping and then adding the text_info movieclip to a scroll_box movie clip then adding the scroll_box to the _myCanvas movieClip. I want to mask the data but am not getting the results I though I should.
_myCanvas = getChildByName("myCanvas") as MovieClip;
_myCanvas.height = 369.10;
_myCanvas.width = 596.15;
_myCanvas.x = 114;
_myCanvas.y = 259.05;
var MyClass:Class = ApplicationDomain.currentDomain.getDefinition("MyScrollElement"开发者_如何学编程) as Class;
_myScrollElement = new MyClass();
var scroll_box = _myCanvas.addChild(_myScrollElement);
for (i = 0; i < myXML.Row.length(); i++){
var item:text_holder = new text_holder();
scroll_box.addChild(item);
var _data = myXML.Row[i];
//add xml data to text fields
move each textbox to
current_y_right = current_y_right + 131;
item.x = current_x_right;
item.y = current_y_right;
}
var myMask = getChildByName("myMask") as MovieClip;
myMask.height = 369.10;
myMask.width = 596.15;
myMask.x = 114;
myMask.y = 259.05;
_myCanvas.mask = myMask;
But the text that is being displayed still shows outside the mask area. Any help would be great.
Well - I'm not quite clear how you're adding items to the stage (on the timeline?) - if your instance name is set in the IDE, you don't need to reassign an instance name, just use it. Also = be sure you are typing all variables. Several were not, and that may very well be a problem (flash may be making assumptions, also).
As far as the mask goes, I can only assume this is an object on the stage. Make sure "embed fonts" is selected. This might also be an issue of the mask not being at the right depth (your newly create objects are essentially over the mask). I might recommend just creating a new Sprite at runtime and doing your masking that way.
Without looking at the project, hard to say, beyond that.
_myCanvas.height = 369.10;
_myCanvas.width = 596.15;
_myCanvas.x = 114;
_myCanvas.y = 259.05;
var MyClass:Class = ApplicationDomain.currentDomain.getDefinition("MyScrollElement") as Class;
var scroll_box:DisplayObject = new MyClass() as DisplayObject;
_myCanvas.addChild(scroll_box);
for (i = 0; i < myXML.Row.length(); i++){
var item:text_holder = new text_holder();
scroll_box.addChild(item);
var _data:String = myXML.Row[i];
current_y_right = current_y_right + 131;
item.x = current_x_right;
item.y = current_y_right;
}
var myMask:Sprite = new Sprite();
myMask.graphics.beginFill(0x00ff00, 0);
myMask.graphics.drawRect(114, 259.05, 369, 596);
myMask.graphics.endFill();
addChild(myMask);
_myCanvas.mask = myMask;
Masking text fields that do not have the fonts embedded is problematic in flash. Make sure you embed the fonts OR try using a TLFTextField if possible. I'm not 100% sure but I think those issues are solved in the TLFTextField. So once again, embedding fonts == surefire way to fix, TLFTextField possible but unproven fix.
精彩评论