Copy link to clipboard
Copied
I have a problem with localToGlobal, by using the responsive publish Settings.
In the stage there is a Movieclip named "car" in this Movieclip ist a nested Movieclip named "wheel"
I want to get the Position of wheel from the view of the stage, so my code is in the first frame of the stage
var p = this.car.wheel.localToGlobal(0,0);
This works fine if you dont publish with responsive size, and the canvas is in the upper left corner of the browser window.
Can you help me?
The problem is that the values you get from localToGlobal are affected by the scaling of the stage, where as the position of objects are not. Here's a function that I wrote, which you can use instead of calling localToGlobal on a symbol.
...// The function
function LocalToGlobal (_symbol) {
var point = _symbol.localToGlobal(0, 0);
// Makes the x and y values not affected by the responsive scaling
point.x /= stage.scaleX;
point.y /= stage.scaleY;
return point;
}
// Example
var globalP
Copy link to clipboard
Copied
The problem is that the values you get from localToGlobal are affected by the scaling of the stage, where as the position of objects are not. Here's a function that I wrote, which you can use instead of calling localToGlobal on a symbol.
// The function
function LocalToGlobal (_symbol) {
var point = _symbol.localToGlobal(0, 0);
// Makes the x and y values not affected by the responsive scaling
point.x /= stage.scaleX;
point.y /= stage.scaleY;
return point;
}
// Example
var globalPosition = LocalToGlobal(this.mcParent.mcChild);
this.mc.x = globalPosition.x;
this.mc.y = globalPosition.y;
Copy link to clipboard
Copied
Thank you very much 🙂