I'm creating a game, and most is going well. However it often has a button on a certain frame which should make it go to a certain frame and play. In my research I found the following solutions
- possible to hide the button on frame 1 and run code (need to know how to do this see).
- Only add the listener of the button on the frame in question ( I don't understand this one, did they mean: coding inside the timeline instead of inside a package)
source: a stackoverflow solved question
I also found this stackoverflow question link 2 this link shows a bit about hiding buttons, however I think it's not meant for inside a package. But I changed that see below.
a snippet from my code based on the example from the above link
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class DocumentClass extends MovieClip
{
public var b1:Boolean = false;
public var b2:Boolean = false;
public function DocumentClass()
{
init();
}
private function init():void
{
button1.addEventListener(MouseEvent.MOUSE_DOWN, checkButton);
button2.addEventListener(MouseEvent.MOUSE_DOWN, checkButton);
private function checkButton(e:MouseEvent):void
{
if(e.target.name == button1) b1 = true;
else b2 = true;
gotoAndPlay(3);
}
on frame 3 for example I could then perhaps do the same as in the above link:
buttonA.visible = false;
buttonB.visible = false;
if (b1) buttonA.visible = true;
if (b2) buttonB.visible = true;
EDIT: I tried out the above code and it works, but my problem is not solved yet (see below).
So here is my question: I need advice/information about how to better use the above code. Reason is; I don't think the above code is correct for what i want (see below).
The above code doesn't work (I think) on buttons placed on frames beyond frame 1 which is a problem.
I need to have a number of frames without (visible) buttons for a intro, then on frame 5 for example a menu with a button that goes to next frame and stops [stop();] and on frame 6 a button that plays the next frames till end.