Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem making a button in flash

Started by kake_fisk Dec 19, 2010 at 8:36 AM 4 replies 600+ views
Original Post
kake_fisk
kake_fisk
Okay, I've been thaught that using a document class in Flash is the "good practise". But now everything is very different than using the timeline's actions.

I'm trying to make a button that takes you to a different frame when you click on it. It changes image when you hover over it and such, but nothing happens when you click on it. The button instance is called btn_start.

This is my code:
package{	import flash.display.*;	import flash.events.*;	import flash.utils.*;	import flash.system.*;		public class main extends MovieClip	{		public var btn_start:MovieClip = new MovieClip();				public function main():void		{			stop();			loaderInfo.addEventListener(ProgressEvent.PROGRESS, evLoaded);			addChild(btn_start);			btn_start.addEventListener(MouseEvent.MOUSE_UP, evStart);		}				private function evStart(event:MouseEvent):void		{			gotoAndStop(3);		}				private function evLoaded(event:ProgressEvent):void		{			if (event.bytesLoaded == event.bytesTotal)			{				gotoAndStop(2);			}		}	}}


Does anybody know what I'm doing wrong?
Visit my website ?
Sacred Water
Monkan
Monkan
Hi,

this bit here

private function evStart(event:MouseEvent):void
{
gotoAndStop(3);
}

wont this make the main movieclip go to frame 3, what happens there, have you specified main with frames???

do you want btn_start.gotoAndStop(3);??

What is suppose to happen when you click on it?
"To know the road ahead, ask those coming back."
AdrianC
AdrianC
I think you're going to want to replace:

btn_start.addEventListener(MouseEvent.MOUSE_UP, evStart);

with

btn_start.addEventListener(MouseEvent.CLICK, evStart);
.

MOUSE_UP activates when no mouse button is pressed. And thats almost at all times, so I'm guessing that's messing up your code.
Angex
Angex
Quote:
MOUSE_UP activates when no mouse button is pressed. And thats almost at all times

Mouse up events are dispatched when a mouse button's state changes from down -> up, over an InteractiveObject.

The flash player does not constantly produce these events is no button is pressed.

I'd try putting a trace into "evStart" to check the function is invoked when you click the button.

Also make sure "enabled" & "mouseEnabled" for the buttons MovieClip are "true".


AdrianC
AdrianC
I guess you're right, I was thinking about something else.

kake_fisk
kake_fisk
I think I'm doing everything wrong, because I don't want to create a new button actually. But I have given up on using document class and I'm just going to use the timeline instead. But thank you for replying at leat. :)
Visit my website ?
Sacred Water

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.