Skip to main content
Known Participant
June 28, 2008
Answered

Action Script 3

  • June 28, 2008
  • 1 reply
  • 697 views
Hi,

I recently completed a class in animation for multimedia. The final project was to develop a splash page, skip button, a website home page and at least (5-6) internal pages. All of the navigation had to work and we could only use Flash CS3 (no java script, no html, etc).

My project turned out the way I wanted except in one aspect. All of my Action Script runs across the top frame-by-frame. So, if I have a page with some links on it I placed my code for a button above that page. Looking ahead, I would prefer to have all of my code in one place rather than strung along the top frame-by-frame.

When I try to put multiple lines of code together (say I have 5 buttons on a page and I want to put all of the event listeners and gotoAndPlay code for all 5 buttons in one place), my movie basically breaks.

Isn't there a way to combine the Action Script for the entire Flash movie (one timeline) in one place? Or, must I string my code out frame-by-frame?

Thanks,

mindforge

This topic has been closed for replies.
Correct answer Andrei1-bKoviI
You can combine it into one function:

1 reply

Inspiring
June 28, 2008
Hi,

There are other ways to organize your code. For instance, you can combine the code into classes and classes into packages. I personally prefer not to put any code onto the timeline.

If you still prefer to place the code on the time line and if I understood your task correctly, you can add the same listener to all the buttons and then read inside the listener where event came from by reading target or currentTarget. Then you do what you need depending on the source.

Hope it helps.
mindforgeAuthor
Known Participant
June 28, 2008
Hi,

So, right now I can click on a keyframe in the Action Script line in the main time-line. Below is an example of the Action Script I wrote for (2) buttons on the same page. If I were to create (1) listener for all buttons on that page how would that change the way I write the following (2) events?

-------------------------Action Script below-----------------------------------------

function mouseDownHandler57(event:MouseEvent):void {
gotoAndPlay(475);
}

btnUserIf.addEventListener(MouseEvent.CLICK, mouseDownHandler57);


function mouseDownHandler58(event:MouseEvent):void {
gotoAndPlay(485);
}

btnCopyWrite.addEventListener(MouseEvent.CLICK, mouseDownHandler58);
Andrei1-bKoviICorrect answer
Inspiring
June 28, 2008
You can combine it into one function: