0

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...

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;
    }
}

}

Thanks!

---added---

Things I've tried:

  • Using a vector instead of an array.
  • Setting tileList[count1] to a variable and then calling that variable.
  • Removing the randomSort.
  • Removing count1 and calling the array element directly (ie, tileList[5]).
7
  • 1
    Have you tried using a Vector instead of an Array? And what exactly are you trying to accomplish, or rather, why does it concern you how Tweenlite treats Object references? Commented Dec 4, 2014 at 7:26
  • I have not tried a vector. I have 16 "tiles" on the screen and I want them to randomly be removed one by one with each button click. All of the code works if I replace "(tileList[count1]" with "tile1" or "tile2", but not when I pull the same name from an array. Commented Dec 4, 2014 at 13:19
  • 1
    That certainly is strange behavior. Out of interest, what type of Object are those tiles? Sprite/Movieclip, or something custom? Something drawn in Flash Pro? As a workaround, you could do the following, in the first line of the function nextButtonClick : var o:Object = tileList[count1]; TweenLite.to(o,5,{y:700,alpha:0}); So you will first get a reference to the object, then use that reference in TweenLite, instead of using it directly in TweenLite. Commented Dec 4, 2014 at 13:26
  • The tiles are movieclips. I tried the Object workaround and got the following error - "Error: Cannot tween a null object.". Commented Dec 4, 2014 at 22:30
  • 1
    How did you create these tiles? Where do they come from? Commented Dec 5, 2014 at 7:27

1 Answer 1

0

After hours of searching I stumbled on Convert String into an object instance name

and got the following solution from it (tested and working!)

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});
Sign up to request clarification or add additional context in comments.

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.