Actionscript 3: Simple Button - actionscript-3

I am working on a project in which a button is clicked, and the frame jumps and stops at a certain area. The button I have is called cancelmenu_btn. It is spread over 1 keyframe (over 5 frames) on an actions layer. The coding for the back button is:
menuback_btn.addEventListener(MouseEvent.CLICK, menubackClick);
function menubackClick(event:MouseEvent):void{
gotoAndStop (2);
}
Yet, the back button only works on one of the frames - frame 3. I have a link to my project:
https://skydrive.live.com/embed?cid=9AB08B59DCCDF9C6&resid=9AB08B59DCCDF9C6%21110&authkey=ALkJwkJaKg7ypI0
What am I doing wrong with the menuback_btn?

There are a few things you have to check if you want the button active. First, make sure your code is on the first frame because it does not become active until that frame hits.
Second, make sure your button is also on the first frame, but then it will associate your btn.addEventListener(Function) correctly.

Related

Strange bug. AS3 button

Strange bug with every my button on stage.
When mouse over to my button - button go to frame 2.
When mouse click to button - button first go to frame 1, after to frame 3.
Button have right, full bounding box. My .fla document not have code. Just one button on stage. Previously, I had no such problem. It appears a few months ago ...
I would need to see your code for proof, but this is probably because of a bad event listener.
Check to make sure you're not listening for a MouseEvent.MOUSE_OVER. Listen for a MouseEvent.MOUSE_CLICK to handle your function properly.

AS3 Making a button work on one scene and does nothing on all other scenes.

I basically have 50 buttons and 50 scenes. Each scene has a corresponding button that is "correct". When a user clicks the correct button, I want it to go to the next scene AND also make that button not-clickable anymore. I have everything functioning except for the not-clickable part and this is an issue because whenever i click on a state that already has been selected as the right answer, it'll jump me back to the question that was supposed to follow it. I'd show my code, but it is just 50 buttons and a buttonClick function and that's it.
Thanks in advance.
You could call
yourButton.removeEventListener(MouseEvent.CLICK,yourFunction);
or you could call
yourButton.mouseEnabled = false;
yourButton.mouseChildren = false;
Hard to help without any code.

ActionScript 3.0 - coding next button, but it skips to the next next page

I'm trying to create a simple flash trivial site where each page has a previous, and next button.
My previous and next buttons seems to work fine when you click them to walk through the movie. (ie. next-> next-> next -> next... ie. prev->prev-> prev->...)
But when I use the 2 buttons together.
The last next should bring me back to the page where I cliked on the 2nd next, but instead it brings me to the page after.
For example:
page 1 (pressed next)-> page 2 (pressed next)-> page 3(pressed previous)-> page 2 (pressed next) -> give me page 4 (It should give me page 3)
Here is my code for one of the pages:
stop();
previous_button.addEventListener(MouseEvent.MOUSE_DOWN, returnToMarineInvertebrate);
function returnToMarineInvertebrate(event:MouseEvent):void{
gotoAndStop("MarineInvertebrate");
}
hint_button.addEventListener(MouseEvent.MOUSE_DOWN, goToFishHint);
function goToFishHint(event:MouseEvent):void{
gotoAndStop("FishHint");
}
next_button.addEventListener(MouseEvent.MOUSE_DOWN, goToFossil);
tail.addEventListener(MouseEvent.MOUSE_DOWN, goToFossil);
function goToFossil(event:MouseEvent):void{
gotoAndStop("Fossil");
}
I think my logic is correct, but I'm not sure what's wrong. Any help would be appreciated! Thank you!
This is a rather hit-and-miss bug in Flash that I've faced down a few times. If you are working with stop() on the target frame, gotoAndStop(targetFrame) will have mixed success.
Instead, you're going to want to call gotoAndPlay();
The reason for this is, in some cases (not all), gotoAndStop() is going to cause Flash to ignore the scripts. That stop call coming from gotoAndStop() can sometimes overshoot by a single frame, usually if stop() is already there.
Thus, if you switch to gotoAndPlay(targetFrame), and let your stop() commands handle braking, you should be fine.

Draggable menu containing non-draggable buttons with AIR

First off, I'm pretty novice when it comes to Flash and AS3.
I am trying to create a displayObject that contains 12 buttons for a mobile app. Since there are twelve buttons that will all open up into seperate menus they obviously all won't fit on a mobile devices screen. This is why I want to have all of the buttons on one display object that can be dragged up and down to show the buttons not currently displayed on the screen.
I am running into numerous problems while attempting this.
1) If I make the object containing the buttons draggable, which is behind the buttons, I can't click it through the buttons in order to drag it(unless I hit a sweet spot where there aren't any buttons but this isn't efficient for the user).
2) If I make the object containing the buttons draggable and put it in front of the buttons then I can't click the buttons in order to open the menus and access what is contained within them.
3) For some reason all of the buttons are seperately draggable when I don't want them to be. For example, I click anywhere on the screen (whether the touchID point is on a button or not) to move the entire list of buttons and if I happen to be clicking a button then, instead of moving the entire list, it moves that one button.
So the main question here is "How can I create a list of buttons and scroll through the list using a drag method (such as the settings menu on your phone) without dragging the buttons apart from each other." So the containing display object is draggable, and the buttons are clickable.
Some guy named Glenn does a good job with his example: http://rabidgadfly.com/2010/03/as3-clickable-button-inside-a-draggable-movie-clip/
However, if you click the yellow button in his example you can drag it out of the gray box. I want my button to remain stationary relative to the gray box. So you can move the gray box but the yellow button remains in the same location within the box but you cant drag the button around within the box.
I am not familiar with accelerometer events for the smartphones, but I do have an idea on how to fix this with regular actionscript 3 listeners. (You can just convert these to whatever is used by smartphone listeners)
A solution that comes to mind is to have a mouse down listener and a mouse up listener on the whole drag-able box. And when a mouse down event fires, you start a timer to go off in about a quarter of a second, and when it does you then set up a enter frame (or a timer based) function that fires every frame. This will update the whole box's position every frame corresponding to the current mouse location (your dragging box effect) and when the mouse up listener fires, it stops the dragging (and at this points, if the mouse is up, then the user is not touching the screen at all).
Also add a mouse click listener to every button. This way, with the quarter of a second timer, you KNOW that if the user simply wants to click a button, then they will click, leaving less that a quarter of a second between the mouse down and mouse up events (so that the dragging never starts) and the button is only clicked. And if the user holds the mouse down for more than a quarter of a second, then you KNOW that they must be trying to drag the whole thing.
This seams like the only way to differentiate between a user wanting to drag the box, and the user wanting to click a button inside it.
Obviously it does not have to be a quarter of a second, it can be any length of time that you want, it could even be no time at all, but then this might mess up things when people only want to click the button and accidentally slides it when clicking.
If you have any questions or problems, please comment and i'll try to help.

Flash buttons flicker continuously when compiled

I am looking for some help with Flash (CS5 version). I have a situation where if try to put a button on the stage with visible differences in the up/over/down/hit states, when I compile the document into a .swf, the button will continuously flicker through each state in order very quickly. Also, if I break the AS3 code in the Main class file, hidden parts of a slider bar component will flicker between visible and not. I'm talking Japanese-style, seizure-inducing flicker here. I've searched my code for recursive function calls and tried deleting and re-adding components and buttons, but to no avail. Any ideas on what could be up?
Well, it seems to me you aren't using stop() to stop the button at the frame you want.
If it isn't this, then there is some error with your ActionScript, which will show up in the output panel, so check that.
When you say 'button' is it an instance of the Button Class and have you set the instance type to Button?
i.e.
Select the button in your library panel, right click and choose 'Properties'. Then set the Type to Button.
Next, select the instance of the button on the stage, open the Properties panel and just underneath where you type the instance name you should see a drop down menu containing MovieClip, Button and Graphic. Set it to Button.