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

Flash EventListener Question

Guest
Jan 17, 2013 Jan 17, 2013

Copy link to clipboard

Copied

Hi Everyone,

If you had time for a Flash Event Lister question, I'd be most grateful.

a) Quick overview -

I'm creating an app for iPads, and using Flash CS6 and air.

I'm using simple code snippet Touchevents.

I have a Scene with 5 characters on the screen which when touched will play a short individual animation each.

Frames 1-100 are a loop animation which is also waiting for a touch event by a User (i.e. plays from frame 1 to frame 100 then goes back to frame 1).

Inside Frame 1 of the Actions layer, I have added 5 Touch EventListeners (just using standard Code Snippets) for each of the 5 characters that can be touched by the User.

I use a 'gotoandplay("LABELNAME");' within each EventListener, which will play each Character's unique animation, located later in the same timeline via 5 specific frame Label names. After each animation plays, I send it back to frame 1 again, to wait for another touch event on a Character.

e.g. Frame 1-100 main loop, Frame 101-150 is "Bob Character" Label, Frame 151-200 is "Jane Character" Label etc etc, with the last keyframe for each label ending with a "gotoandplay(1);" to send it back to the start.

B) The Goal -

I need to be able to press a Character onscreen, and while it's animation is playing, be able to touch another Character which will stop playing the current animation, and play the newly pressed animation instead.

C) The Issue -

The EventListeners I've set up work well, however I noticed that upon touching certain Characters onscreen, I can't touch a second Character immediately and play it's animation, as the first one is still playing until complete.

Still with me?   The plot thickens, because upon further investigation I found that according to its position along the timeline (using Labels for each Character's animation block), some animations are in fact able to 'interrupt' others, but others won't.

In summary -  I found that a Character's Label/animation located along the timeline AFTER the current playing, CAN interrupt the current animation when touched. However trying to touch a Character whose Label/animation is located in the timeline BEFORE the current playing one, will NOT interrupt the current one playing.

I did a bit of a 'dodgy' test and sort of got around this by repeating the EventListener code for the Character Touchevents within the first frame of each new Label animation section.  i.e. so it was listening again for Character touch events in each Label section.

This however seems like a lot of repeated Listener code throughout the timeline.

D)  Thoughts -

This has me wondering if I have put the Eventlistener code in the proper location (i.e. inside Frame 1 of the Actions layer), and whether there is a 'global' location for the Scene that I can put them in so that they are always listening throughout the timeline, not matter at what point it is playing.

I really hope that makes sense.

Thanks so much, I appreciate your time.

Hanky

TOPICS
ActionScript

Views

2.1K

Translate

Translate

Report

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
Guru ,
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

Follow this instruction and debug your code.

If the Output Window gives any warnings/errors return and post.

Votes

Translate

Translate

Report

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
Guest
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

Hi there,

Thanks for your reply and suggestion.

I've followed those instructions, and I don't receive any errors at all.

Votes

Translate

Translate

Report

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
Guru ,
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

This has me wondering if I have put the Eventlistener code in the proper location (i.e. inside Frame 1 of the Actions layer), and whether there is a 'global' location for the Scene that I can put them in so that they are always listening throughout the timeline, not matter at what point it is playing.

It`is usually a good practice to place all your code on the first frame of an application.

From your description, though, I could easily come up with 5 different scenarios, what the "Root of all Actionscript-Evil" is in your case, so you should do the following:

1.Make a screenshot of your whole timeline, with at least the first 200 frames visible and post it.

2.Show the actual stage at frame 1.

3.Copy the code of your first frame and post it also

Votes

Translate

Translate

Report

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
Guest
Jan 18, 2013 Jan 18, 2013

Copy link to clipboard

Copied

LATEST

EDIT/UPDATE -

I have resolved this issue, and have included the details below.

I note that the following touch behaviour was occuring -

- If the "Bowl" animation is playing, touching the "Fruit" or "Paper" objects WILL interrupt "Bowl" playing, and play the recently touched animation.

- If "Fruit" animation is playing, touching "Paper" WILL interrupt the Fruit animation, and play the "Paper" animation.

- If "Paper" animation is playing, touching "Fruit" will NOT interrupt the Paper animation.

- If either the "Paper" or "Fruit" animation is playing, the "Bowl" animation will NOT interrupt either.

- "Picture1" and "Picture2" animations are able to interrupt each other, which I find very strange given my previous observations (in initial post) of Labels located beforehand in the timeline.

Upon investigating futher I identified the following as the issue -

- Issue for "Bowl" not being able to interrupt other animations is due to the Touch area layer not continuing on for the length of the timeline.

I had stopped it at the end of the main start loop, meaning it wasn't present or being 'listened for' throughout the rest of the timeline.

   

- Issue for "Fruit" not being able to interrupt anything from the "Paper" animation onwards is because I noticed that from this keyframe onwards, I'd just inserted a grouped version of the Fruit image, NOT the Symbol version I'd used at the start main loop section to which I had assigned the EventListener in the Frame 1 code.

 

- To help other people in same situtations, I found the easiest thing to do to resolve this, was for each object on screen that required a Touchevent, I simply created a separate "NAME Touch" symbol box, each on their own named Layer, and inserted it over the object.

I then ensured that each of those "Touch" symbol layers ran for the complete length of the timeline, therefore ensuring always listening.

EventLister Issue.jpg

Frame 1 code

/* Tap Event

Tapping on the symbol instance executes a function in which you can add your own custom code.

Instructions:

1. Add your custom code on a new line after the line that says "// Start your custom code" below.

The code will execute when the symbol instance is tapped.

*/

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

Animation_Page2_Picture1.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler_46);

function fl_TapHandler_46(event:TouchEvent):void

{

    // Start your custom code

    // This example code reduces the transparency of the object by half upon each tap event

    gotoAndPlay("Picture1");

    // End your custom code

}

/* Tap Event

Tapping on the symbol instance executes a function in which you can add your own custom code.

Instructions:

1. Add your custom code on a new line after the line that says "// Start your custom code" below.

The code will execute when the symbol instance is tapped.

*/

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

Animation_Page2_Picture2.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler_45);

function fl_TapHandler_45(event:TouchEvent):void

{

    // Start your custom code

    // This example code reduces the transparency of the object by half upon each tap event

    gotoAndPlay("Picture2");

    // End your custom code

}

/* Tap Event

Tapping on the symbol instance executes a function in which you can add your own custom code.

Instructions:

1. Add your custom code on a new line after the line that says "// Start your custom code" below.

The code will execute when the symbol instance is tapped.

*/

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

Animation_Page2_Fruit.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler_47);

function fl_TapHandler_47(event:TouchEvent):void

{

    // Start your custom code

    // This example code reduces the transparency of the object by half upon each tap event

    gotoAndPlay("Fruit");

    // End your custom code

}

/* Tap Event

Tapping on the symbol instance executes a function in which you can add your own custom code.

Instructions:

1. Add your custom code on a new line after the line that says "// Start your custom code" below.

The code will execute when the symbol instance is tapped.

*/

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

Animation_Page2_Paper.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler_50);

function fl_TapHandler_50(event:TouchEvent):void

{

    // Start your custom code

    // This example code reduces the transparency of the object by half upon each tap event

    gotoAndPlay("Paper");

    // End your custom code

}

/* Tap Event

Tapping on the symbol instance executes a function in which you can add your own custom code.

Instructions:

1. Add your custom code on a new line after the line that says "// Start your custom code" below.

The code will execute when the symbol instance is tapped.

*/

Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

Animation_Page2_Bowl.addEventListener(TouchEvent.TOUCH_TAP, fl_TapHandler_51);

function fl_TapHandler_51(event:TouchEvent):void

{

    // Start your custom code

    // This example code reduces the transparency of the object by half upon each tap event

    gotoAndPlay("Bowl");

    // End your custom code

}

Votes

Translate

Translate

Report

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