Movieclip does not listen to positioning with x and y property

I am seeing an issue where my class that extends movieclip, after instantiation does not listen to the positioning properties x and y. However it does listen after 0.5 seconds. Because I can see the instance recognizing the properties after using Actuate.tween at 0.5 seconds.

I had got similar problem earlier where if I remember correctly, had solved this problem by adding the movieclip to the stage before accessing the x or y property. But now I have tried so many ways but nothing is working.

Has anyone experienced similar thing before?

Perhaps a library (like Actuate) is fighting your values so it is setting it’s tween values over the top over your manual settings

Can you try Actuate.stop() or Actuate.apply on the instance?

I mean to say, Actuate is actually solving the problem. In fact I removed Actuate and replaced it with Lib.setTimeout . So instead of animating it’s directly positioning the movieclips at the desired values of x and y.

So the issue is that for some reason movieclip instance’s x and y property don’t reflect changes if I put it directly beneath the instantiation code. However if I delay the execution of that code, it’s working fine.

My code has got complex, so it will take me time to extract the problem area. But in short the problem looks like this:

var mc:MovieClip = new MovieClip();
mc.x = 100 ; mc.y = 100;

This is not working.

But I have to modify it this way either using Actuate or Lib.setTimeout

var mc:MovieClip = new MovieClip();
Lib.setTimeout( function(){
mc.x = 100 ; mc.y = 100;
},1500 );

I am tracing the values and everything looks fine. The only thing weird is, it’s not reflecting it on the canvas.

I figured out the problem.

I was storing the values of various types of DisplayObjects in Array<Dynamic>

Accessing back the array directly eg. arr[i].x or arr[i].width give null value.

Instead of accessing directly, Reflect.setProperty and Reflect.getProperty will need to be used in such case where Array is declared dynamic.

So instead of arr[i].x = 100 it will become

var arr:Array<Dynamic> = new Array<Dynamic>();
Reflect.setProperty ( arr[i], "x", 100)
1 Like