actionscript-3flashactionscriptflex4.5starling-framework

Array error in actionscript 3.0


Here i tried to move card around by using the x and y axis it shows the following error:

TypeError: Error #1010: A term is undefined and has no properties. at GamePlay/moveNext()[D:\TrainingAS3\GamePlay.as:71]

When I click the button for move cards it shows in this statement

Globe.self.realstage.TweenLite.to(anEntry['card'], .4, { 
 x:anEntry['x'], y:anEntry['y'], onComplete:moveNext } );


package 
{
    import flash.display.MovieClip;
    import flash.events.TimerEvent;
    import flash.events.MouseEvent;
    import com.greensock.*;
    import com.greensock.easing.*;
    import Globe;

    public class GamePlay 
    {
        var currentEntry:int = -1;

        var aList:Array =
            [
                {card:Globe.self.realstage.joker_mc, x:605.55, y:195.45},
                {card:Globe.self.realstage.king_mc,  x:323.80, y:298.45},
                {card:Globe.self.realstage.queen_mc, x:45.85, y:213.95},
                {card:Globe.self.realstage.a_mc,     x:605.55, y:195.45},
                {card:Globe.self.realstage.ten_mc,   x:323.80, y:298.45},
                {card:Globe.self.realstage.five_mc,  x:45.85, y:213.95},
                {card:Globe.self.realstage.two_mc,   x:605.55, y:195.45},
                {card:Globe.self.realstage.nine_mc,  x:323.80, y:298.45},
                {card:Globe.self.realstage.four_mc,  x:45.85, y:213.95},
            ];

        public  function onClick(e:MouseEvent):void
        {
            // Unsubscribe to avoid the mess with second click.

            Globe.self.realstage.click_mc.removeEventListener(MouseEvent.CLICK, onClick);


            // Start process.
            moveNext();
        }

        public  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.
            trace(card);

            Globe.self.realstage.TweenLite.to(anEntry['card'], .4, { 
     x:anEntry['x'], y:anEntry['y'], onComplete:moveNext } );


        }


}

Could you please someone Elaborate this one ...


Solution

  • That error means that one of the following objects are null/undefined:

    self.realstage.TweenLite or anEntry

    Looking at those objects and seeing you are importing com.greensock.*, the issue is with TweenLite.

    TweenLite is a class, which means it cannot be a property of realStage (which is how you are trying to access it).

    To remedy the situation, just reference the TweenLite class directly since you've already imported it:

    TweenLite.to(anEntry['card'], .4, {x:anEntry['x'], y:anEntry['y'], onComplete:moveNext } );
    

    To further understand what's going on, you could research the difference between Static properties and methods and regular properties and methods.