0

How do I get the var sliderthumb to replace [sliderthumb] in my code below? Thanks for your help.

var sliderthumb:String = "foo";

function natureThumb(){

Sprite(naturepage.sliders.[sliderthumb].getChildAt(1)).height = Sprite(naturepage.sliders.[sliderthumb].getChildAt(1)).width = 65;

}

3 Answers 3

1

Just remove the dot.

Sprite(naturepage.sliders[sliderthumb].getChildAt(1)).height
Sign up to request clarification or add additional context in comments.

Comments

1

There is a method for displayObjectContainer called getChildByName that allow to access child display objects by its name. Hope this helps!

var sliderthumb:String = "foo";

function natureThumb(){

Sprite(naturepage.sliders.getChildByName(sliderthumb).getChildAt(1)).height = Sprite(naturepage.sliders.getChildByName(sliderthumb).getChildAt(1)).width = 65;

}

Comments

0

Well both answers provided can sorta be right depending on how the OP set things up, but wanted to add some clarification. First I would modify the code to be this:

var sliderthumb:String = "foo";

function natureThumb(){
    var sp:Sprite = naturepage.sliders.[sliderthumb].getChildAt(1) as Sprite;
    sp.height = sp.width = 65;
}

if you setup the object like

var mySprite:Sprite = new Sprite();
mySprite.id = "foo";

then this will work (assuming you want the second child of the object foo which is a child of sliders)

function natureThumb(){
    var sp:Sprite = naturepage.sliders[sliderthumb].getChildAt(1) as Sprite;
    sp.height = sp.width = 65;
}

if you instead setup your object like

var mySprite:Sprite = new Sprite();
mySprite.name = "foo";

then this will work

function natureThumb(){
    var sp:Sprite = naturepage.sliders.getChildByName(sliderthumb).getChildAt(1) as Sprite;
    sp.height = sp.width = 65;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.