-
1. Re: on mouseclick logic for timeline animation
Ned Murphy Jun 29, 2012 4:35 PM (in response to DKNMSIS)The best way to write it is to start with the outline you just gave and figure out each aspect of it in code. If necessary, build each step of it one step at a time, testing as you go.
-
2. Re: on mouseclick logic for timeline animation
DKNMSIS Jun 29, 2012 5:07 PM (in response to Ned Murphy)Thanks for the advice, just a few questions though
*there are 6 animations in total so would I start each of these functions from mouse events on those individual buttons?
*Would it be a good idea to use enter_frame events to track where the timeline is and to control other things, or can i just use the mouse events on its own to tell the animation to go back 2 frames on a click etc..
*also since i'm relativly new at actionscript I'm having trouble with my document class, maybe im entering functions wrong or just not understanding how i need to write actionscript
but i am unsure where to put my new functions and listeners and such.
currently this is the line i want to put in
levelMC.childmc.childmc.childmc.button1.addEventListener(MouseEvent.CLICK, animationcycle);
public function animationcycle(event:MouseEvent):void
{
trace("when i click on the button this text should show up")
}
I would assume i can put it in here
Document class
package
{
Imports
public class main extends movieclip
{
public function main()
{
caching bitmaps and other things i want done on startup
eventlistener called Listener
}
public function Listener ()
{
trace("various lines of code");
}
This is where i assume I can just drop
levelMC.childmc.childmc.childmc.button1.addEventListener(MouseEvent.CLICK, animationcycle);
public function animationcycle(event:MouseEvent):void
{
trace("when i click on button1 this text should show up")
}
}
}
When I do that I'm getting a acess of undefined propery "levelMC" and "animationcycle"
-
3. Re: on mouseclick logic for timeline animation
Amy Blankenship Jun 29, 2012 5:53 PM (in response to DKNMSIS)1 person found this helpfulhttp://active.tutsplus.com/articles/general/flashs-underrated-graphic-symbol/I wouldn't try to add an event listener on something that deeply nested in the constructor of its great-great-great-grandparent. I wouldn't want to count on the fact that the distant decendent would both exist and be on stage when you run that code.
Instead, I'd just add a listener on the document class for a bubbling event. This event could either be a click, and look like this:
protected function onSomethingClicked(e:MouseEvent) {
var something = e.target as DisplayObject;
if (something && something.name=='button1') {
//do something
}
}
or, your button could dispatch a more descriptive event, and you could listen for that. Note that you don't need to create a custom event if all you want to know is that something specific happened.
For example:
//in main document in some function like the constructor
addEventListener('repair', onRepairRequest);
//else where in main document
protected function onRepairRequest(e:Event):void {
//do something
}
//in childmc.childmc.childmc
button1.addEventListener(MouseEvent.Click, requestRepair);
protected function requestRepair(e:MouseEvent) {
dispatchEvent(new Event('repair'));
}
Note that Movie Clip Symbols in the library can also have document classes, so you might find it useful or convenient to create this logic closer to the button (in childmc or childmc.childmc etc.). Also note that if you're going to listen for a bubbling click, you need to set button1's mouseChildren property to false so that you don't miss clicks on its label.
One thing you might want to consider is that a lot of logic really flattens out if you can take advantage of Graphic symbols instead of Movie Clips http://active.tutsplus.com/articles/general/flashs-underrated-graphic-symbol/.
Good luck!
-
4. Re: on mouseclick logic for timeline animation
DKNMSIS Jun 29, 2012 6:22 PM (in response to Amy Blankenship)wow thats a really helpful answer, I'll take the next few days to start implementing that, thanks a ton!
-
5. Re: on mouseclick logic for timeline animation
Amy Blankenship Jun 29, 2012 6:36 PM (in response to DKNMSIS)You're welcome. I noticed you mentioned bitmap caching. You might also enjoy these posts from my blog http://flexdiary.blogspot.com/search/label/Bitmap
-
6. Re: on mouseclick logic for timeline animation
Amy Blankenship Jun 29, 2012 6:37 PM (in response to DKNMSIS)I noticed there was a mistake in my code.
protected function requestRepair(e:MouseEvent) {
dispatchEvent(new Event('repair'));
}
should be
protected function requestRepair(e:MouseEvent) {
dispatchEvent(new Event('repair', true));//so it will bubble
}
-
7. Re: on mouseclick logic for timeline animation
DKNMSIS Jun 29, 2012 8:00 PM (in response to Amy Blankenship)awesome, you are an actionscript goddess! thanks a ton, i will definatly check out your blog, cheers!