Copy link to clipboard
Copied
Where should I put my code, on the buttons and other items in question, or in a separate Layer, referencing the items I need...?
Background :
I'm REALLY new to Flash with Adobe. I've used SwishMax a little in the past, but nothing of recent.
At work there's a project where I'm getting to use FlashPro CS6 and I've run into an odd issue with code to move forwards, backwards, and back to the beggining on 3 different buttons.
It's in a layer called Actions, and on frame 1 - And remember... uber newbie here folks, so forgive any glaring issues in my code that most people would see quickly...
//NEXT BUTTON
NEXT_BUT.addEventListener(MouseEvent.MOUSE_DOWN, nb_mouseDownHandler);
function nb_mouseDownHandler(event:MouseEvent):void
{
this.nextFrame();
}
//MAIN MENU BUTTON
MAINMEN.addEventListener(MouseEvent.MOUSE_DOWN, mm_mouseDownHandler);
function mm_mouseDownHandler(event:MouseEvent):void
{
gotoAndStop(1, "Scene 1");
}
//BACK BUTTON
BACK_BUT.addEventListener(MouseEvent.MOUSE_DOWN, bb_mouseDownHandler);
function bb_mouseDownHandler(event:MouseEvent):void
{
this.prevFrame();
}
The code for the first two work's exactly as I need, the code for the back button, initially it only appeared on from the second frame onwards, but during debugging I've popped it on all pages. On the first frame, it takes you back to a black page with nothing on it, on all others it does absolutely nothing...
Another question as I've written above, should my code be in a separate layer regerencing the items it needs to affect, or... as a colleague told me in a ridiculously over the top brimming with distaste, create layers for each item, or groups of items and place the code in there... which to me, see's odd...
Thanks once again in advance, and I'm sorry to post such a newbie question, but the internet gives mixed anwers, not specific to my situation.
Tim.
Copy link to clipboard
Copied
Never distribute your code on multiple layers, different scenes or inside nested MovieClips.
Best solution: Separate the code completely from your fla (which should hold only the assets for your movie), which you achieve by making a document class
2nd Best solution: Put all your code on a separate Layer of frame 1 Scene 1
Copy link to clipboard
Copied
Thank you moccamaximum, thats going to make some interesting reading...
Copy link to clipboard
Copied
In AS3 you cannot put code on buttons and other items like you could with AS1 and AS2. Beyond that, your choices are to place code in the timeline frame(s) or in separate actionscript files. While there are a number of recommended best practices, what usually works best is whatever you are able to understand and work with at the time. While there are benefits to having all code located in one place (a frame or a file) since it makes finding it much easier, when you are creating a timeline-based design, that is not always a possible/practical approach.
Over time you will gain experience with the different approaches and can make the choice based on that experience.
Copy link to clipboard
Copied
Ned, a nice list of options and confirmation that I can't put code on the items, like I would in other apps.... AS3 does seem very different to other styles that I've used... hopefully this wont make it too much of a nightmare to learn!
Copy link to clipboard
Copied
If you were placing code on objects, with AS3 that nightmare is behind you.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now