Question

I am using actionscript 3 to make a point and click game. On frame 1 there are two buttons, button 1 and 2. On frame 3 there are two buttons, button A and B.

I want it so that after I click button 1 on frame 1, button A on frame 3 will be hidden or when I click button 2 on frame 1, button B on frame 3 will be hidden. The buttons that are hidden do not do anything when you click them.

thanks in advance

Was it helpful?

Solution

If you try to remove something that is not in the display list yet Flash will thrown an error. I guess the best solution here is setting up a timeline variable to keep track of which button you have pressed. Something like this:

on frame 1

var b1:Boolean = false;
var b2:Boolean = false;

button1.addEventListener(MouseEvent.MOUSE_DOWN, checkButton);
button2.addEventListener(MouseEvent.MOUSE_DOWN, checkButton);

function checkButton(e:MouseEvent):void
{
   if(e.target.name == button1) b1 = true;
   else b2 = true;

   gotoAndPlay(3);
}

on frame 3

myButtomA.visible = false;
myButtomB.visible = false;   

if (b1) myButtomA.visible = true;
if (b2) myButtomB.visible = true;

OTHER TIPS

There are many ways to remove an object from the display list, or otherwise hide it from view. For example:

button1.addEventListener(MouseEvent.MOUSE_DOWN, removeButton);

function removeButton(e:MouseEvent):void
{
 buttonContainer.removeChild(otherButton);
}

You could also set the target buttons "visibility" property to false. Very very simple, and you should be able to modify this snippet as needed.

On another topic.

I always urge people away from developing interactions on the timeline. It just confuses things, especially when you have such potent object oriented tools available in AS3...

Either way - Cheers and good luck.

  • update - In response to the OPs last comment:

Sure thing - although its a fairly deep question, depending on your experience. The main thing is getting involved with AS3's Object Oriented features, and driving the majority of your application via code alone.

Projects look like this: the Fla functions mostly as a container for assets (and if you utilize embeds, not even that), with a single, empty timeline frame. The main document class is then responsible for initiating and constructing all aspects of the project - everything from the load and control of data to the creation and addition of display list objects to establishing and controlling user interactions. Classic Package / Class design is used to create, potentially, dozens or hundreds of individual .AS files. The timeline is still used to create complex animations, but rarely involve any code (save a stop(); here or there).

When I was just learning this - I got a good book, and hit the googles a lot, to figure out the essentials of AS3, and just kind of went from there. Make a few simple projects, and you can see how indepth you can get, and quickly.

The benefit from working like this can not be overstated.

Let me know if you have any further questions. Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top