5 Replies Latest reply on Jun 3, 2009 2:50 PM by Ned Murphy

    Help with symbol rotation and upper-left coordinates

    Missing Code Level 1

      I want to be able to rotate a symbol on the center of my choosing (or even the very center of the image/symbol), yet still maintain the upper left corner as 0,0. Is this possible? It seems I can only have one or the other.

       

      My project is an image (inside a MovieClip symbol) that moves around and rotates depending on the direction of travel. Only problem is, it rotates funny. And then when I center/adjust the rotation of the image inside the symbol, its origin is no longer in the same place, and I have to put in extra numbers to compensate. I assume the crosshairs are the (0,0) as well as the center point or rotation. I'm fine with that being the (0,0), but how can I move the rotation/pivot point elsewhere? I tried using the Free Transform Tool to move the white dot to the center, but to little avail.

       

      Any tips? Thanks!

        • 1. Re: Help with symbol rotation and upper-left coordinates
          Ned Murphy Adobe Community Professional & MVP

          As far as I know, you have to choose one or the other.  If centered rotation is important, then center your 0,0 and use the compensating values if you need to locate the ever-moving upper left corner.

           

          I don't know if loading the moiveclip into an empty movieclip might provide a solution you'd like or not.  You could rotate the centered movieclip inside, and use the containing movieclip for the x/y values.  It might be worth playing with to see what happens.

          • 2. Re: Help with symbol rotation and upper-left coordinates
            Missing Code Level 1

            Ok, I tried your "empty MovieClip" method, and it seems to work well. Please look at my code and see if I am doing it the most efficient way.

             

            These are symbols in my library:

            Clean (MovieClip) - Black stage sized rectangle to clear the buffer.

            Square (MovieClip) - Blue (100x100) Square centered on the crosshairs (so it can rotate on its center)

             

            // BEGIN CODE //

            var bitmap:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,true,0xff000000);                    
            var buffer:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,true,0xff000000);
            var image:Bitmap = new Bitmap(bitmap);
            addChild(image);
            var clean:MovieClip = new Clean();
            var container:MovieClip = new MovieClip();
            var square:MovieClip = new Square();
            container.x = stage.width/2-square.width/2;
            container.y = stage.height/2-square.width/2;
            container.addChild(square);
            square.x = container.width/2;
            square.y = container.height/2;
            addEventListener(Event.ENTER_FRAME,onEnterFrame);

            function onEnterFrame(event:Event):void {
                square.rotation+=5;
                buffer.draw(clean);
                buffer.draw(container, container.transform.matrix);
                bitmap.draw(buffer);
            }

            // END CODE //

             

            A few questions I had about the code:

            1. On "var square:MovieClip = new Square();" should I keep MovieClip like I have, or use Square?

            2. If I make a Square.as file later, and have to use Square, do I retain MovieClip properties from my library symbol?

            3. For memory management, do I need to set my MovieClips to null, or anything else like that in some finishing function?

             

            Sorry about all the questions, I just want to get it right the first time. Thanks.

            • 3. Re: Help with symbol rotation and upper-left coordinates
              Ned Murphy Adobe Community Professional & MVP

              1. If Square is the class name, then you should use Square instead of MovieClip.  If the class file was automatically created, it likely has a MovieClip or Sprite in its code.

               

              2. I'd like to say yes, but I'm class illiterate (I can troubleshoot them to a degree, but haven't ventured into making any of my own of any significance.  Chances are you are best to define any variables/functions associated with the Square in the AS file rather than in the library object it represents.

               

              3. I'm not sre what you mean by finishing function.  If you are removing objects at some point, you should cancel (null) any references to them.

              1 person found this helpful
              • 4. Re: Help with symbol rotation and upper-left coordinates
                Missing Code Level 1

                About #3, here's what I meant:

                 

                As far as I know in some languages occasionally memory from variables is not released upon program termination; therefore, the system memory total is slowly reduced every time you run the program. I guess the computer assumes it is still in use, and views it as unavailable for use. Some languages/compilers automatically free up your memory, and some do not. I'm not sure if Flash/ActionScript does this for you when the program ends, or if you have to do something like assign a null to arrays, bitmaps, etc. at the end of the program.

                 

                Thanks again for your help with the original question!

                • 5. Re: Help with symbol rotation and upper-left coordinates
                  Ned Murphy Adobe Community Professional & MVP

                  Hah!... you're hitting another of my weakspots (video and sound are on that list too)...  Honestly though, unless you're creating a multitude of objects,  I wouldn't worry too much about housekeeping.  If you're interested, you might do a search on AS3 Grabage Collection and read thru some of what's to say in that realm.