4 Replies Latest reply: Jun 10, 2013 1:22 PM by Departure RSS

    Trying to dynamically Rotate a Dynamically Created Movie Clip

    Departure Community Member

      Hi As3 Gods...

       

      I want to rotate a movieClip that is created and animated by a function in the same Code window.

       

      var electron:MovieClip=new MovieClip

      createElectron(electron)

      electron.rotation=90 ------> I expect the whole animated MovieClip to rotate. nothing happens though.

       

      // I have a function that receives the electron and build / animates it

      function createElectron( receives the MovieClip + more parameters ):MovieClip

      { bunch of codes

      returns the MovieClip

      }

       

      -------

       

      It is achievable if I create an external MovieClip through library, and put the createElectron codes inside that movieClip and export it to ActionScipt and then rotate it, but then i donno how to assign Parameters to an external function in the movieClip when i call the electron, i want to be able to tell the function what is the radius, speed, etc. I have never tried creating Classes, donno if it helps me here or not. I think i m failing to sort of WRAP the MOvieClip and the animation inside, so i can rotate the whole thing when returned.

        • 1. Re: Trying to dynamically Rotate a Dynamically Created Movie Clip
          Ned Murphy CommunityMVP

          You'll need to show more of your code to support your saying "nothing happens though".  Setting the rotation property to be 90 should work.  Try showing a simplified version of the code whith something to show for the electron object that supports your saying it is not rotated when the createElectron function is done with it.

           

          The function is passed a reference to the electron so is does not need to return it.  The function will target the electron that you created in the first line.

          • 2. Re: Trying to dynamically Rotate a Dynamically Created Movie Clip
            Departure Community Member

            var electronsH:Array=new Array

            var electron:Sprite = new Sprite();

             

            buildElectronBeam(8,50,50)

             

            function buildElectronBeam(atom,repeatHorizontal,wide)

            {

                         For loop{

                               var electron2:Sprite = new Sprite();

                              singleElectron(radius,4,electron2)  // here i send electron2 to be animated and built up in the called function

                              electron2.rotation=90 // This does rotate the electron but not the animation defined for it.

                               electronsH[h]= electron2

                               addChild(electronsH[h]) // shows that animation is still horizontal

                          }

            }

             

            function singleElectron(radius,pixel,electron:Sprite)

            {

            createPoint(pixel)

                function createPoint(radio:uint)

                {

                    electron.graphics.beginFill(0xFFFFFF,1)

                    electron.graphics.drawRect(0,0,pixel,pixel)

                    addChild(electron)

                    electron.addEventListener(Event.ENTER_FRAME, movepixels) 

                 }

             

                 function Animatepixels(e:Event)

                 {   pixel starts to spin on a horizontal line}

            }

             

             

            I think my problem is I dont know how to attach this animation to be part of the MovieClip so i Can rotate the whole thing. What i was trying to achieve here is to say flash "Consider whatever going on in this singleElectron function as my MovieClip" but as we both see, electron is the movieClip and animate function just performs something without being a part of MovieClip itself.

            • 3. Re: Trying to dynamically Rotate a Dynamically Created Movie Clip
              moccamaximum Community Member

              Are you using a motion tween to do your animation, besides the enter frame function?

              • 4. Re: Trying to dynamically Rotate a Dynamically Created Movie Clip
                Departure Community Member

                @Moccamaximum

                 

                No instance or symbol created...No animation on timeline. The code is placed on first frame of the Stage.

                 

                I do not want to use TWEEN class because i m defining my own patters for animating the .x and .y properties of Electron. As you noticed, the Animate function here is still detached from the electron movieClip and the quest is to how make this animation an attached motion of the movie clip so the whole thing can be rotated together.