K_G
K_G

Reputation: 2901

as3 dynamic Names for StageText / NativeText

does anyone know how to dynamically assign a name to NativeText / StageText as i am trying to build a dynamic interface instead of hardcoding it in, any help would be appreciated!

Upvotes: 0

Views: 418

Answers (3)

K_G
K_G

Reputation: 2901

if anyone is trying to return text values with NativeText a StageText wrapper. they will need to edit;

https://github.com/cantrell/StageTextExample/blob/master/src/NativeText.as

add a public get function -

public function get text():String {
return this.st.text;
}

then you can return the NativeText values normally -

nt.text

Upvotes: 0

You should keep references to the dynamically created instances of StageText as you cannot get it by querying the display list (as it is not on display list). You can have the vector of of StageText

var m_vStageTextInstances:Vector<StageText>;

Then after you will just iterate over this vector.

Upvotes: 1

Daniel MesSer
Daniel MesSer

Reputation: 1181

Here's some example code that does what you want inside the iterate-function

public class IterationTest extends Sprite {

    public function IterationTest() {
        createObjects();
        iterate();
    }

    private function createObjects():void {
        for (var i:int = 0; i < 1000; i++) {
            addChild(new TextField());
            addChild(new MovieClip());
        }
    }

    private function iterate():void {
        var numTextObjects:int = 0;
        for (var i:int = 0; i < this.numChildren; i++) {
            var child:DisplayObject = getChildAt(i);
            if (child is TextField) {
                //do your stuff here
            }
        }
    }

}

Upvotes: 0

Related Questions