Reputation: 83
Let's say I have a classA that is linked to movieClip in the library:
package {
public class ClassA extends MovieClip {
public function constructor() {
}
}
}
There is another movieClip linked to another class that I want to add inside ClassA
package {
public class ClassA extends MovieClip {
private var obj:MovieClipFromLibrary();
public function constructor() {
obj = new MovieClipFromLibrary();
obj.x = obj.y = 0;
addChild(obj);
}
}
}
Now, the problem is the movieclip that is linked to ClassA is small in size and placed at the center of the stage (like a dialog box on Android). But the "obj" movieClip is a rectangle and covers the entire stage. When I place it at (0,0), it gets positioned at the (0,0) of the "ClassA" MovieClip. What I want to do is the position it at (0,0) of the "Stage". How can I accomplish this?
Upvotes: 0
Views: 43
Reputation: 52133
Use globalToLocal()
to convert stage (global) coordinates to local coordinates:
var stageTopLeft:Point = this.globalToLocal(new Point(0, 0));
object.x = stageTopLeft.x;
object.y = stageTopLeft.y;
Upvotes: 1