Skip to main content
Inspiring
September 17, 2017
Answered

localToGlobal responsive

  • September 17, 2017
  • 2 replies
  • 668 views

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?

This topic has been closed for replies.
Correct answer RandomlyFish

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;

2 replies

Inspiring
September 17, 2017

Thank you very much :-)

RandomlyFishCorrect answer
Inspiring
September 17, 2017

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;