The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 4 of 4

Thread: TweenMax Arrays

  1. #1

    TweenMax Arrays

    Problem as follows...

    I'm creating a flash game that throws rotten fruit at a band. When the game starts you select what type of fruit you want. There are 10 different fruits. I created a empty movie clip called ---var ammoCon:MovieClip = new MovieClip(); to hold whichever fruit the use selects by the addChild(tomato_mc); method.

    Right now the problem I have is that when I "fire" the fruit at the band I cannot fire another shot till the first shot has hit it's target and been removed from the display list. If I do try to fire another shot the one currently in flight is removed instantly.

    What I need is to fire the fruit as fast as I want. I know I need to use an array. The problem is I can't figure out how to store the TweenMax Tweens into an array. And I'm not sure that's my only problem, I think there are a few other code mistakes. I know how to add the fruit to the empty movieClip, but not sure how to add this object to a tween array.

    ps TweenMax is the only Tween lib I can use because it contains the besier curve method

    Please help. If you need further description of the problem I will give it.
    here is the code that has had me stumped for a few days..

    Code:
    //-------buildAmmo-------//
    function buildAmmo(ammo:MovieClip):void{
        //trace(ammoCon.numChildren);
        if(ammoCon.numChildren == 1){
            ammoCon.removeChildAt(0);
        }
        //ammoCon.addChild(ammo);
        currentAmmo = ammo;
        trace(currentAmmo);
    }
    
    function fireFruit(e:MouseEvent):void{
            
            randomX = Math.random() * 649;
            //ammoCon.addChild(currentAmmo);
            //ammoCon.x = randomX;
            //ammoCon.y = stage.stageHeight;
            
            splatAreaX = mouseX;
            splatAreaY = mouseY;
            
            
            swoosh1Fx.play();
            
            ammoConArray[ammoConArrayCounter] = new AmmoConMC();
            ammoConArray[ammoConArrayCounter].addChild(ammoCon);
            ammoConArray[ammoConArrayCounter].x = randomX;
            ammoConArray[ammoConArrayCounter].y = stage.stageHeight;
            ammoConArray[ammoConArrayCounter].visible = true;
            ammoCon.visible = true;
            //-------the best tween Engine ever!!!!!!!!!!!!!!!!!
            TweenMax.to(ammoConArray[ammoConArrayCounter], ammoSpeed, {x:splatAreaX, y:splatAreaY, onComplete:checkHitArea, bezier:[{x:randomX ,y:stage.stageHeight - 100}], orientToBezier:true});
            //trace(ammoConArray.length);
            //trace(ammoConArray[ammoConArrayCounter].getChildAt(0));
            //trace(ammoConArray.length);
            ammoConArrayCounter++;
            if(ammoConArray.length >= 7){
                ammoConArray.pop();
                ammoConArrayCounter--;
            }
    
    }

  2. #2
    I'm on vacation at the moment, typing this from a hotel, so I didn't have time to comb through your code to troubleshoot, but I figured I'd chime in and mention that it's easy to keep track of TweenMax instances because whenever you call TweenMax.to() or TweenMax.from(), it returns a TweenMax instance. So you could populate an Array like:

    Code:
    var myTweens = new Array();
    var t1 = TweenMax.to(my_mc, 1, {x:"200"});
    myTweens.push(t1);
    That code could be simplified, but I wanted it to be readable so you get the concept. If you need to kill a particular tween, just call TweenMax.removeTween(myInstance); which could look like TweenMax.removeTween(myTweens[0]). Or you can force it to completion using the complete() method, like myTweens[0].complete(true). See the documentation for more details at www.TweenMax.com.

    Hope that helps!

  3. #3
    ok im sure how tween max works and how your depth is organized but thats what i can see because you cant have to items at the same depth so when you throw one tomato the reason it gets replaced is there is no different depth so try putting in a depth changer that makes it so that they dont all end up on the same layer or the item will just replaced.

  4. #4

    Solved

    Thanks Guys I finally figured it out with a little help from both your post. TweenMax is a great Tween Engine. Thanks Green Stock. I need to study it a bit more to understand how it's working. I believe it's creating a new tween instance each time I call it. I need to figure out if the tweenMax instance gets destroyed when the tween is complete. And if not remove it accordingly. Just haven't got to it yet.

    Here is my working code.


    Code:
    //-------fireFruit-------//
    function fireFruit(e:MouseEvent):void{
            
            randomX = Math.random() * stage.stageWidth;
    
            switch(currentAmmo){
                case "tomato":ammoCon = new TomatoAmmo();break;
                case "lettuce":ammoCon = new LettuceAmmo();break;
                case "eggs":ammoCon = new EggAmmo();break;
                case "rawSteak":ammoCon = new RawSteakAmmo();break;
                case "potato":ammoCon = new PotatoAmmo();break;
                case "tomatoCan":ammoCon = new TomatoCanAmmo();break;
                case "grandpasUnderwear":ammoCon = new GrandpasUnderwearAmmo();break;
                case "diaper":ammoCon = new DiaperAmmo();break;
                case "bottleRocket":ammoCon = new BottleRocketAmmo(); break;
            }
            
            
            ammoCon.x = randomX;
            ammoCon.y = stage.stageHeight;
            
            splatAreaX = mouseX;
            splatAreaY = mouseY;
            
            swoosh1Fx.play();
            
            addChildAt(ammoCon,1);
            
            ammoCon.visible = true;
            
            //-------the best tween Engine ever!!!!!!!!!!!!!!!!!
            TweenMax.to(ammoCon, ammoSpeed, {x:splatAreaX, y:splatAreaY, onComplete:checkHitArea, bezier:[{x:randomX ,y:stage.stageHeight - 100}], orientToBezier:true});
    }
    Last edited by zanemx; May 14th, 2008 at 05:43 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012