Skip navigation
Currently Being Moderated

on mouseclick logic for timeline animation

Jun 29, 2012 4:24 PM

Tags: #button #movieclip #actionscript3 #mouse_event #logic #mouseclick

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




  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.


whats the best way to write what I want to happen

  • Currently Being Moderated
    Jun 29, 2012 4:35 PM   in reply 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.

    Mark as:
  • Currently Being Moderated
    Jun 29, 2012 5:53 PM   in reply to DKNMSIS 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 = as DisplayObject;

       if (something &&'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 symbol/.


    Good luck!

    Mark as:
  • Currently Being Moderated
    Jun 29, 2012 6:36 PM   in reply to DKNMSIS

    You're welcome. I noticed you mentioned bitmap caching. You might also enjoy these posts from my blog

    Mark as:
  • Currently Being Moderated
    Jun 29, 2012 6:37 PM   in reply 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


    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points