views:

27

answers:

1

How to bring the current target into the movie clip?

If we can set the current target into "selectMovieClip" variable then i believe we should be able to rotate or manipulate it as a MovieClip.

Please copy the script below and you will see what I mean. Currently I can't rotate it.

Please tell me what is wrong with my script. Thank you.

import flash.display.MovieClip;

 /*create multiple MovieClip*/
 for(var i:int = 0; i < 10; i++){
  var widthSquare:int = 100; 
  var heightSquare:int = 100;
  var square:MovieClip = new MovieClip(); 
  square.graphics.lineStyle(1,0x0000CC);
  square.graphics.beginFill(0xCCCCCC);
  square.graphics.drawRect(0,0,widthSquare,heightSquare); 
  square.graphics.endFill();
  square.name = "RotableClip_"+i;
  square.x = 100 + (widthSquare*i); 
  square.y = 400;
  addChild(square);
 }

 //SET MOVIECLIP
 var selectMovieClip;//declare veriable
 function onMousePress(evt:MouseEvent):void{
  if( evt.target.name.indexOf("RotableClip_")==0){//only allow RotableClip_ to rotate
   selectMovieClip=evt;
   trace("Selected movie clip" + evt.target.name);
  }
 }
 stage.addEventListener(MouseEvent.MOUSE_DOWN, onMousePress); 


 //Rotate MovieClip
 function MouseMove(evt:Event):void{
    rotateTarget();//recreate the menu 
  }
 stage.addEventListener(MouseEvent.MOUSE_MOVE, MouseMove);
 function onMouseRelease(evt:MouseEvent):void {
  rotateTarget()
 }

 //rotateTarget OR at onMousePress 
 //How do we bring the movie clip into the below and rotate it.
 function rotateTarget(){
  selectMovieClip.rotation += 90;
  trace("Rotate the movie clip");
 }
+1  A: 

In onMousePress() , you've assigned selectMovieClip to evt, not to evt.target ! Since selectMovieClip is not typed , Flash won't throw an error. Also,if you'd trace selectMovieClip as opposed to tracing evt.target.name, you would have picked up the error!

PatrickS
Well i have not executed your code but i think PatrickS is directing you the bug.. Try and check that.
Muhammad Irfan
so, how do we assign the movieClip to "selectMovieClip", this is the intance name.
dngo
i think it got it. evt.target
dngo
yes, this is it!
PatrickS