1 Reply Latest reply on Jul 14, 2009 2:41 AM by aniFlasher

    Passing coordinates relative to stage into a nested MC



      I am so very stuck, and need your help with relative coordinates please.


      I am building a project where I have 15 'islands' inside one big 'ocean' movie clip.

      I created navigation buttons so you can explore the Ocean movie clip and look around the islands.

      my problem comes when i want to 'zoom into an island'



      So basically on the stage i have a movie clip called- Ocean_mc, and inside it are 15 movie clips, one of them (for this example) is a movie clip called GreenIsland_mc.


      when a user clicks the GreenIsland_mc it needs to expand and place itself centre stage, then when clicked again in needs to colaps back to where it came from. The problem is that when GreenIsland_mc expands it needs to expand to coordinates relative to the stage, but when I shrink it back again it need to find the original coordinates relative to its place inside the Ocean_mc movie clip.


      The code I am using right now does everything according to the coordinates relative to the movie clip, so it has no problem going back to where it came from inside the Ocean but it always changes it's 'zoomed in' position according to where the Island is on stage

      So my question is- how do I make sure that when I assign the island it's zoomed in coordinates they are always going to make it open centre stage?


      This is my code-


      // the open button call


      Ocean_mc.GreenIsland_mc.ZoomIn_btn.onPress = function() {





      // the open button function


      this.openIsland = function(theIsland:Object): Void


      originIslandY = theIsland._y;

      originIslandX = theIsland._x;

      theIsland._x = 400;

      theIsland._y = 170;

      theIsland._xscale = 180;

      theIsland._yscale = 180;



      // the closing button call-


      Ocean_mc.GreenIsland_mc.ZoomOut_btn.onPress = function() {





      // the closing button function

      this.closeIsland = function(theIsland:Object):Void


      theIsland._x = originIslandX;

      theIsland._y = originIslandY;

      theIsland._xscale = 100;

      theIsland._yscale = 100;




      Thank you for any advice you might have!!

        • 1. Re: Passing coordinates relative to stage into a nested MC
          aniFlasher Level 1

          Ok, I managed to solve it myself 


          Basically I think I manually created the .localToGlobal thing (but i might be wrong on that).


          1) I simply defined the ocean_mc original coordinates-

          It wasn't a straight forward 0,0 because my movie was not properly centred, so I simply did a trace statement to find where the ocean_mc thinks it is.


          2) Then I defined the original coordinates of a central zoom point for the island-

          This was done by a non-sophisticated trial and error where I clicked to zoom in the island to set coordinates, and simply changed them little by little till i found the right place on stage, I am sure there is a beautiful smooth way to calculate those coordinates but I found the dirty trial and error way very quick


          3) When an Island was clicked to be zoomed, I checked the placement of the ocean_mc clip in relation to it's original place and added that difference to the island's original centre points.


          That's it.


          In code terms-




          // So I started by setting original coordinates for the ocean_mc movie clip-


          var origOceaonX:Number = -200;

          var origOceaonY:Number = -310;





          // Then setting the original coordinates for the zoomed in island

          // (this is basically the coordinated that will place the island movie clip centre stage if it is clicked before anything is moved )-


          var origIslandX:Number = 180;

          var origIslandY:Number = 270;


          // and then I defined 4 new vars-

          // two to hold a new adjustments for the centre point for the islands-


          var centrePointAdjstX:Number;

          var centrePointAdjstY:Number;


          // and two for setting the new centre point for the islands-


          var newCentrePointX:Number;

          var newCentrePointY:Number;





          // and then when ever the zoom in button was clicked I looked where the ocean_mc movie clip was in relation to it's starting point and simply adjusted // the island's centre coordinates accordingly


          // the open button function (called when the zoom-in button is clicked)


          this.openIsland = function(theIsland:Object): Void


          originIslandY = theIsland._y;   <---this is for placing the island back to where it came from when you close it

          originIslandX = theIsland._x;


          centrePointAdjstX = Ocean_mc._x - origOceaonX;    // <---- see how much the oceaon_mc clip moved from it's original spot

          centrePointAdjstY = Ocean_mc._y - origOceaonY;

          newCentrePointX = origIslandX + centrePointAdjstX  // <--- add the change to the original centre point of the island to adjust

          newCentrePointY = origIslandY + centrePointAdjstY

          theIsland._x = newCentrePointX; // <--- the island centres itself 'to the stage' even though it's containing movie clip was moved about.

          theIsland._y = newCentrePointY;


          theIsland._xscale = 180;

          theIsland._yscale = 180;




          Thats it