Search code examples
actionscript-3

as3 - Changing position checking for in IF statement


I am trying to catch X.Y positions with an IF statement, and IF the coordinates are true I want it to go on to the next set of coordinates. In the code below I attempted my best but I keep getting the "Cannot assign to a non-reference value." Error.

public function onDd(event:TimerEvent):void  
    { 
        if (this.rootClass.world.strMapName == "test" && a1.x = a1.x = 327.1 && a1.y = 249.65)
            {
                a1.x = 360.7; 
                a1.y = 204.25;
            }
        else if (a1.x = 410.15 && a1.y = 204.25)
            {
                a1.x = 360.7; 
                a1.y = 204.25;
            }

    }

Solution

  • You have used a wrong comparison operator

    If you want to compare two values you must use == or ===

    So your code will become:

    public function onDd(event:TimerEvent):void { 
        if (this.rootClass.world.strMapName == "test" && a1.x == 327.1 && a1.y == 249.65) {
                a1.x = 360.7; 
                a1.y = 204.25;
            }
        else if (a1.x == 410.15 && a1.y == 204.25) {
                a1.x = 360.7; 
                a1.y = 204.25;
            }
    }