Jump to content
Search Community

How to return an array element as a variable in TweenLite?

jdfinch3 test
Moderator Tag

Recommended Posts

The code is below. When Tweenlite is called it treats "tileList[count1]" as a string instead of a variable name. However the trace seems to return what I would expect (tile1, tile2, tile3...). If I remove "tileList[count1]" from the tween and replace it with a direct call to the MovieClip (tile1, tile2, etc) the code works perfectly...

 

Things I've tried:

  • Using a vector instead of an array.
  • Setting tileList[count1] to a public and local variable and then calling that variable.
  • Removing the randomSort.
  • Removing count1 and calling the array element directly (ie, tileList[5]).
  •  
public class wtpMain extends MovieClip {

    public var tileList:Array = new Array(tile1,tile2,tile3,tile4,tile5,tile6,tile7,tile8,tile9,tile10,tile11,tile12,tile13,tile14,tile15    ,tile16); 
    public var count1:int = 0;


    public function wtpMain() {
        nextButton.buttonMode = true;
        nextDis.mouseEnabled=false; 

        nextButton.addEventListener(MouseEvent.CLICK, nextButtonClickh);

        tileList.sort(randomSort);

    }

    public function nextButtonClickh(event:MouseEvent):void {
        nextButtonClick();
    }

    public function nextButtonClick():void{


        TweenLite.to(tileList[count1], 5, {y:700, alpha:0});
        trace(tileList[count1]);
        count1++;

    }

    public function randomSort(objA:Object, objB:Object):int{
        return Math.round(Math.random() * 2) - 1;
    }
}

}
Link to comment
Share on other sites

I'd still like to find a proper way to call an array element in tweenlite, but I found a work around by changing the following 2 lines of code.

public var tileList:Array = new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); 
TweenLite.to(this["tile"+tileList[count1]], 5, {y:700, alpha:0});
Link to comment
Share on other sites

hmm, not sure I'm following you, anytime you wrap something in quotes it will be used as a String. 

 

The code you provided should work

var count1:Number = 0; 
TweenLite.to(tileList[count1],  5, {y:700, alpha:0});

Feel free to zip up a reduced fla and post it here using "more reply options".

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...