How to create an instance of an object in action script 3?
I have created several objects as a class. Now I have a layer called action script an in the first frame I create an instance of an object with action script (addChild and so on). Then that instance can create other objects. The problem is that when I set object.x and object.y it shows this in relation to the position of the first object. How can I have that object create an instance of another object independent of it?
When you p.addChild(c), c becomes a child of p, and all its coordinates are relative to p. That’s the intention.
If you DON’T want to use relative coordinates, you must not make c be a child of p. To use global coordinates, c must be a child of stage:
var c = new YourClass();
stage.addChild(c);
Or, you can make c be a child of p, but convert the coordinates from global to local:
var X = 100; var Y = 200;
var c = new YourClass();
p.addChild(c);
var point = p.globalToLocal(X, Y);
c.x = point.x; c.y = point.y;