views:

23

answers:

1

Hi guys.... I am trying to get the percentage x coordinate of a MC. For example, My MC is 500px wide and 20px height. When I clicked the part of my MC, I want to get the percentage of my MC' x coordinate... (20% will be 100px of my MC...)..Anyone knows how to do it?? Thanks..

my code

progressBa.addEventListener(MouseEvent.CLICK, barClick);

  private function barClick(event:MouseEvent):void{
    perct=this.mouseX/progressBa.Width;  //not sure how to do it....
   }
+1  A: 

I'm not very familiar with Actionscript, but I used the trace(event) function to see what's inside the event:

[MouseEvent type="click" bubbles=true cancelable=false eventPhase=2 localX=202 localY=5 stageX=296 stageY=88 relatedObject=null ctrlKey=false altKey=false shiftKey=false buttonDown=false delta=0]

As you can see, the MouseEvent object has a property called localX, which is the one you need. So, the actual class for the movieclip is:

package 
{
  import flash.display.MovieClip;
  import flash.events.*;

  public class progressBa extends MovieClip
  {
    public function progressBa()
    {
      // Add a mouse event to this, the movieclip called progressBa
      this.addEventListener(MouseEvent.CLICK, clickBar);
    }

    private function clickBar(e:MouseEvent):void
    {
      // Get click location's x-coordinate in percentages
      var percent = 100 * e.localX / this.width;
      trace(percent);
    }
  }
}

To my surprise I was able to click on 100.018...%, maybe because of anti-alias.

Harmen
Nice...Thanks for the helpp......
Jerry