Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-29-2012, 03:42 AM   #1
DKNMSIS
Registered User
 
Join Date: May 2012
Posts: 23
Default on mouseclick logic for timeline animation

So there is a movieclip that goes through certain stages in a Breaking,BrokenLooping,Fixing,brokenPermenant animation cycle

I'm just starting to make the actionscript for it but I'm not sure how to go about it, or if the logic is sound. I am a bit new to actionscript

i assume i can make a function like this
Quote:
function myButtonAction(eventObject:MouseEvent) {
trace("you clicked on the button ");
}
myButton.addEventListener(MouseEvent.CLICK, myButtonAction);
where myButton is the instance of a button movieclip ontop of the movieclip

__________________________________________________ __________

The general idea is that randomly things will break and stick in a broken loop, then you have to start taping the screen to repair it until fixed or else it permanently breaks

*note that the fixing animation cycle is backwards so that positive on the timeline is it slowly breaking - you tap to reverse frames and "repair"


the logic goes like this (at the start of the looping broken animation)
on user input (mouseclick)
-goto frame (xx) (end of fixing animation)
-stop() for 1 second (stopping so it doesnt just enter next animation cycle)
..... -if user input yes (tap/click)
......... -go back one frame [currentframe -1]
......... -stop() for 0.100 seconds then play()
......... - or if time between taps is less than 0.100, then play
..... -if user input is no (no tap/click)
......... -play()


I'm not sure if that handles all the possibilities but i guess ill find out as i go.

does anyone have any advice on how to start this or if i am missing anything?

Last edited by DKNMSIS; 06-29-2012 at 03:44 AM.
DKNMSIS is offline   Reply With Quote
Old 06-29-2012, 12:19 PM   #2
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,833
Send a message via Skype™ to henke37
Default

You should use the enter_frame event to run your animation logic, not the mouse event.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 06-29-2012, 04:05 PM   #3
DKNMSIS
Registered User
 
Join Date: May 2012
Posts: 23
Default

could you explain a little more why i would use that over mouse event?

I assumed the mouse event was used to detect a mouse click which is the basis for my animation changing its cycles

what would an enter frame event do?
DKNMSIS is offline   Reply With Quote
Old 06-29-2012, 06:16 PM   #4
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,398
Default

enter frame event can check the status of the variables and elapsed time on every frame. (continuous updates)
Mouse listeners are only called when the user does something with the mouse.
[afz]snickelfitz is offline   Reply With Quote
Old 06-29-2012, 07:16 PM   #5
DKNMSIS
Registered User
 
Join Date: May 2012
Posts: 23
Default

would that add more strain to the cpu having continuous updating? this is on a ios/android game that is just barely keeping 24fps.

so what your saying is that I use the enterframe event so that when the timeline enters each new frame, it THEN checks for mouse input and follows the same logic above.

is that the right idea?

EDIT: I'm having trouble comprehending this.
If it checks for mouseclicks on each frame then would it only accept one mouseclick per frame as a yes or no function? what happens if you click multiple times per frame using enter_frame.

preferably the effect i'm going for is that the user is battling the timeline tapping to go back frames while the animation is playing. If i use enter_frame thenwont things get messed if the timelines goes backwards? (from taping to go back a few frames)

Last edited by DKNMSIS; 06-29-2012 at 07:28 PM.
DKNMSIS is offline   Reply With Quote
Old 06-29-2012, 07:49 PM   #6
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,398
Default

Flash is either executing code or drawing the screen; never both at the same time.
The enter frame event is keyed to the tempo (current framerate) of your flash movie; it is neither forwards nor backwards; it's akin to the brain listening for heartbeats, then doing something on each beat.
On each frame check the status of your Booleans, current time, current frame, etc... then update the app accordingly.

Not sure about the CPU strain as a result of just listening for enter frame events.
What you actually do on each frame (display-wise) is most likely to be the issue with regard to framerate.
[afz]snickelfitz is offline   Reply With Quote
Old 06-29-2012, 09:48 PM   #7
DKNMSIS
Registered User
 
Join Date: May 2012
Posts: 23
Default

even with 6+ timelines going at the same time its still better to use enter_frame instead of mouse_events? sure it allows for more functionality but for 6 seperate movieclips it seems more efficient to alter the timeline according to mouse clicks and if there isnt any then it just keeps playing the animation
DKNMSIS is offline   Reply With Quote
Old 06-29-2012, 10:52 PM   #8
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,398
Default

I think you are misunderstanding the concept of "frames" as it pertains to the enter frame event.
Flash has an internal "ticker" that is always running at the stage.framerate.
enter frame listeners listen for each tick. (frame)
Many code-based flash apps and games animate content and execute code mainly by listening to this ticker.
ie: there may be no manually created timeline animations or MovieClips at all; just a 1 frame Sprite running (or "ticking") at 24fps.

BTW, depending on the complexity and composition of the objects, running 6 animations at the same time can potentially reduce runtime performance, especially on mobile devices with weak processors.
An enter frame event listener might be the least of your problems in this case.
[afz]snickelfitz is offline   Reply With Quote
Old 06-29-2012, 11:20 PM   #9
DKNMSIS
Registered User
 
Join Date: May 2012
Posts: 23
Default

Oh okay, that makes sense, thanks, I had thought it only worked in the timeline of a movieclip instead of a ticker that ticks for every frame.

As it stands now i have 20+ animations running at once all with movieclips animating inside movieclips. from a graphical standpoint its running much better than i had thought it would with GPU acceleration and caching vectors as bitmaps so I'm just barely keeping it running at 24fps

I had read some optomization guides for adobe air and actionscript can slow things down as well, im just not sure how it compares to the visuals, I just want to keep the AS as efficient as it can be

thanks for the advice once again
DKNMSIS is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:28 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.