• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

localToGlobal responsive

Participant ,
Sep 17, 2017 Sep 17, 2017

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?

Views

490

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Sep 17, 2017 Sep 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 globalP

...

Votes

Translate

Translate
Contributor ,
Sep 17, 2017 Sep 17, 2017

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 17, 2017 Sep 17, 2017

Copy link to clipboard

Copied

LATEST

Thank you very much 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines