0
votes

I need something to happen when positioning of one of my movie clips becomes the same as positioning of the other one. Here is the code i tried to use but doesn't work. Says that "Left side of assignment operator must be variable or property.".

instructions_txt.text = "Pomozite Macku da dodje do cigara!";
var speed:Number = 3;
var pozx;
var pozy;

balloon_mc.onEnterFrame = function() {

if (Key.isDown(Key.RIGHT)) {
    this._x = this._x + speed;
} else if (Key.isDown(Key.LEFT)) {
    this._x = this._x - speed;
} else if (Key.isDown(Key.DOWN)) {
    this._y = this._y + speed;
} else if (Key.isDown(Key.UP)) {
    this._y = this._y - speed;
}
if(pozx = this._x && pozy = this._y)
{


    }
};
cigare_mc.onEnterFrame = function() {
this._x = pozx;
this._y = pozy;
}
2

2 Answers

1
votes

Hope it's not too late, I think your problem is here:

this._x = this._x + speed;
this._x = this._x - speed;
this._y = this._y + speed;
this._y = this._y - speed;

You should use 2 var to change _x and _y Try this:

    instructions_txt.text = "Pomozite Macku da dodje do cigara!";
    var speed:Number = 3;
    var pozx;
    var pozy;
    var baseX = this._x;
    var baseY = this._y;

    balloon_mc.onEnterFrame = function() {

    if (Key.isDown(Key.RIGHT)) {
        this._x = baseX  + speed;
        baseX = baseX + speed;
    } else if (Key.isDown(Key.LEFT)) {
        this._x = baseX  - speed;
        baseX = baseX - speed;
    } else if (Key.isDown(Key.DOWN)) {
        this._y = baseY  + speed;
        baseY  = baseY  + speed;
    } else if (Key.isDown(Key.UP)) {
        this._y = baseY  - speed;
        baseY  = baseY  - speed;
    }
    if(pozx == this._x && pozy == this._y)
    {


        }
    };
    cigare_mc.onEnterFrame = function() {
    this._x = pozx;
    this._y = pozy;
    }
0
votes

You got that error because in your if statement, you've used an assignment operator ( = ) instead of an equality ( == ) one, so you can write :

if(pozx == this._x && pozy == this._y) {
    // ...
}

For more about ActionScript 2's syntax and fundamentals, take a look here.

But, as you're a beginner, you can start learning ActionScript 3 ( which you can use, for example, to create some mobile apps using AIR ... ) instead of the old ActionScript 2 ...

Hope that can help.