Hemanth Raj Hemanth Raj - 5 months ago 43
ActionScript Question

Tweenlite in multiple objects

I tried to move cards to my users they are three members here i have nine cards here my code below.I have used tweenlite to move first three cards moved successfully then rest of cards how can i move to users.

import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;

click_mc.addEventListener(MouseEvent.CLICK, UserOne);



function UserOne(evt:MouseEvent):void
{

TweenMax.to(joker_mc, .5, { x:598.25, y:164.45 , onComplete:UserTwo} );
}

function UserTwo():void
{
TweenLite.to(king_mc, .5, { x:316.50, y:267.90, onComplete:UserThree} );

}

function UserThree():void
{
TweenLite.to(queen_mc, .5, { x:39, y:172} );

}


Anyone knows Please Elaborate this one.

Answer Source

There's no need to create separate code for each of the cards, they are all alike. Create an Array with card + x + y entries, and work with the entries.

import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;

var currentEntry:int = -1;
var aList:Array =
[
    {card:joker_mc, x:598.25, y:164.45},
    {card:king_mc,  x:316.50, y:267.90},
    {card:queen_mc, x:39, y:172},

    // ...
    // and so on
];

click_mc.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:MouseEvent):void
{
    // Unsubscribe to avoid the mess with second click.
    click_mc.removeEventListener(MouseEvent.CLICK, onClick);

    // Start process.
    moveNext();
}

function moveNext():void
{
    currentEntry++;

    // Stop the process if all the cards have been moved.
    if (currentEntry >= aList.length) return;

    // Get the entry.
    var anEntry:Object = aList[currentEntry];

    // Move the card.
    TweenLite.to(anEntry['card'], .5, {x:anEntry['x'], y:anEntry['y'], onComplete:moveNext});
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download