Skip to main content
Participating Frequently
February 1, 2018
Answered

Using js to change movieclip x postion going in opposite direction

  • February 1, 2018
  • 3 replies
  • 2943 views

I'm having a hard time trying to change a movieclip x/y position. When I use js to update the x or y position it goes in the opposite direction I need it to go. For instance if I do myMovieclip.x = 100 it should be translating myMovieclip to right 100 px but instead it moves 100px to the left. But when I use Animate CC GUI to change x position it works fine. This is very confusing. Can anyone please explain? Thanks

    This topic has been closed for replies.
    Correct answer Colin Holgate

    This seems to be correct, and a non-code work around is to double-click on the white circle when using the Free Transform Tool. That make it jump into the top left corner, and after that the code work around isn't needed.

    3 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    February 1, 2018

    Please notice that in HTML5 (Canvas) documents, CreateJS seems to take into consideration the Transformation Point (the white dot accessed with the Free Transform Tool (Q)) not the Registration Point.

    So the IDE and the runtime give different results.

    Colin Holgate
    Colin HolgateCorrect answer
    Inspiring
    February 1, 2018

    This seems to be correct, and a non-code work around is to double-click on the white circle when using the Free Transform Tool. That make it jump into the top left corner, and after that the code work around isn't needed.

    Legend
    February 1, 2018

    randyFuse  wrote

    For instance if I do myMovieclip.x = 100 it should be translating myMovieclip to right 100 px

    No, that code would move myMovieclip to X coordinate 100, which could be left or right (or no motion at all!), depending on where myMovieclip was before that line of code.

    So it's not clear from your post whether you're trying to move a clip to an absolute position, or relative to its current position.

    Colin Holgate
    Inspiring
    February 1, 2018

    mc.x = 100 will set it to be at 100 x. Did you mean mc.x+=100?

    If that's what you meant, is the movieclip inside another movieclip, that is horizontally flipped?

    randyFuseAuthor
    Participating Frequently
    February 1, 2018

    Yes it's in a nested mc and it's not flip horizontally. When I created the parent mc I set the registration point top left. On child mc bounds are 0,0, 300,250 and when I set childMc.x = 100 it goes moves to the left but when I do childMc.x = 200 it moves 100px to right. It looks like its translating from the center of nestMc instead of the left registration point.

    Legend
    February 1, 2018

    So do a trace(childMc.x); before anything else to see what your true centerpoint is, then work with that. There should be no particular reason why it has to be 0.