Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with animation/Hit Test in AS3

New Here ,
Mar 01, 2011 Mar 01, 2011

I am currently developing a game in a school project using Flash CS4 and Actionscript 3.0.  I have searched the web for assistance, but have come up empty.  Here is what I am wanting to do...

I have a 3 by 3 grid on screen.  Each block in the grid contains a movie clip with four targets which cycle through at 24 fps.  Each target with have a different outcome depending on which frame the mouse is clicked.  I do not want the animation to stop after the frame is clicked, however.  There are several different types of targets in the game.  Some add points, some subtract points, one target has the avility to freeze the animations for a set period, and another one is basically an instant game over.  Being as how I could not find any aid via the web prior to this post, I am not even positive that this is possible to code in AS3.0.  Does anyone know if this is possible, and if so, how would I go about coding it?  Any assitance would be great!

TOPICS
ActionScript
700
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Mar 01, 2011 Mar 01, 2011

//if you positioned all your target already on stage, be sure you named them all, skip the next 2 lines and

var target:Target = new Target();

target.name = "target1";

getChildByName("target1").addEventListener(MouseEvent.CLICK, clickHandler);

getChildByName("target2").addEventListener(MouseEvent.CLICK, clickHandler);

....

function clickHandler(e:MouseEvent):void{

     trace(e.currentTarget.name);

    // results possibly in "target1"

      trace(MovieClip(e.currentTarget).currentFrame);

   // results in wh

...
Translate
Mentor ,
Mar 01, 2011 Mar 01, 2011

//if you positioned all your target already on stage, be sure you named them all, skip the next 2 lines and

var target:Target = new Target();

target.name = "target1";

getChildByName("target1").addEventListener(MouseEvent.CLICK, clickHandler);

getChildByName("target2").addEventListener(MouseEvent.CLICK, clickHandler);

....

function clickHandler(e:MouseEvent):void{

     trace(e.currentTarget.name);

    // results possibly in "target1"

      trace(MovieClip(e.currentTarget).currentFrame);

   // results in whatever framenumber the animation of the clicked MovieClip is during the click

}

Based on this clickHandler you can easily write other code that deals with the results

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 01, 2011 Mar 01, 2011
LATEST

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines