Setting default values for object properties in AS3

Posted by Paul T on Stack Overflow See other posts from Stack Overflow or by Paul T
Published on 2010-12-28T20:52:02Z Indexed on 2010/12/28 20:54 UTC
Read the original article Hit count: 125

Filed under:

I'm an actionscript newbie so please bear with me. Below is a function, and I am curious how to set default property values for objects that are being created in a loop.

In the example below, these propeties are the same for each object created in the loop: titleTextField.selectable, titleTextField.wordWrap, titleTextField.x

If you pull these properties out of the loop, they are null because the TextField objects have not been created, but it seems silly to have to set them each time. What is the correct way to do this. Thanks!

var titleTextFormat:TextFormat = new TextFormat();   
    titleTextFormat.size = 10;  
    titleTextFormat.font = "Arial";
    titleTextFormat.color = 0xfff200;

for (var i=0; i<arrThumbPicList.length; i++) {

    var yPos = 55 * i

    var titleTextField:TextField = new TextField();  
        titleTextField.selectable = false;
        titleTextField.wordWrap = true;
        titleTextField.text = arrThumbTitles[i];
        titleTextField.x = 106;
        titleTextField.y = 331 + yPos;

    container.addChild(titleTextField);
    titleTextField.setTextFormat(titleTextFormat);

}

© Stack Overflow or respective owner

Related posts about actionscript-3