actionscript 3 - How to change SWC component's width shown on the Flash IDE? -
i linked item in library .as file.in .as file,i write class this:
public class textarea extends movieclip { ....... public function setwidth(w:number):void { this.width = w; } }
then change item complied clip in library(it same complied ***swc* )**.i add stage , change it's property fire setwidth function.but width doesn't change.what should change movie clip's width?
p.s. child ,a textfield , in item can changed width.
in pic, put swc component on stage , swc have 1 textfield child.
the text field given black border , swc being selected,the blue border bounds.
and print this.width
in text , width auto changed adjust text field.
but blue border want change.it shows on flash panel , stand transform bounds this:
so, don't have trouble change children's data. , found class this:
there livepreviewparent this.parent
. provide live preview of swc on stage.and size change absolutely changed,but think blue border stand livepreviewparent's border.
however, change size of livepreviewparent equal change component's size not blue one.how strange class ! so want know blue 1 livepreviewparent's border? if yes , how change it?
i don't know, how component builded, should have inner logic resize subcomponents/childs.
universal solution, blind resize of every child:
public function setwidth(w:number):void { var i: uint, len: uint = this.numchildren, child: displayobject; for(i; < len; ++i){ this.getchildat(i).width = w; } }
if textarea 1 child:
public function setwidth(w:number):void { textarea.width = w; }
simple textfield container, background , custom padding:
import flash.display.sprite; import flash.text.textfield; import flash.text.textfieldautosize; import flash.text.textformat; public class textcontainer extends sprite { private var _textfield:textfield; private var _padding:int; public function textcontainer(text:string, format:textformat, padding:int = 4) { _padding = padding; _textfield = new textfield(); _textfield.defaulttextformat = format; _textfield.autosize = textfieldautosize.left; _textfield.multiline = true; _textfield.wordwrap = true; _textfield.text = text; addchild(_textfield); _textfield.x = _textfield.y = padding; //default width setwidth(100); } public function setwidth(value:number):void { _textfield.width = value; graphics.clear(); graphics.beginfill(0xf0f0f0); graphics.drawrect(0, 0, _textfield.width + 2*_padding, _textfield.height + 2*_padding); } }
usage:
var textcontainer: textcontainer = new textcontainer("some text here test, more text, multi-line test , resize", new textformat("arial")); desiredcontainer.addchild(textcontainer); textcontainer.setwidth(200);
Comments
Post a Comment