Old 23-11-2007, 20:02   #1 (permalink)
bazzle
Senior Member
 
bazzle's Avatar
 
Join Date: Aug 2007
Location: Derby uk
Posts: 468
Send a message via MSN to bazzle
actionscript linking problem

I'm sure this question has been asked dozens of times before, but I can't find a decent answer to it.

On flash cs3 with actionscript 3.0, how do I apply actionscript to a button.

With 2.0 It's possible but with 3.0 I get this selection can't have actions applied to it.
  Reply With Quote
Old 24-11-2007, 01:40   #2 (permalink)
theRemix
Battery Chicken
 
theRemix's Avatar
 
Join Date: Apr 2007
Location: Hawaii
Posts: 83
Send a message via AIM to theRemix Send a message via MSN to theRemix
create a class for that flash document.

and then include that class file in the "Document Class:" field in the properties.

if it was called Main.as, and you had a button on the root timeline with an instance name of "my_but"
then you can do something like.

Code:
package{ import flash.display.MovieClip; import flash.events.MouseEvent; import flash.display.SimpleButton; class Main extends MovieClip{ public function Main(){ init(); } private function init():void{ var myBut:SimpleButton = my_but; myBut.addEventListener(MouseEvent.CLICK,onClick_myBut); } private function onClick_myBut(event:MouseEvent):void{ trace("you touched my_but"); } } }

of course replace the trace action with whatever you want to happen.

also, i haven't tested this code, i just pulled it out of my_but :P though it should work.


btw. how do you tab text in the browser input text areas?

hth
  Reply With Quote
Old 24-11-2007, 12:56   #3 (permalink)
bazzle
Senior Member
 
bazzle's Avatar
 
Join Date: Aug 2007
Location: Derby uk
Posts: 468
Send a message via MSN to bazzle
That all seems a bit complex as I just want to know how to add actionscript to a button on the stage.

Thanks tho.
  Reply With Quote
Old 24-11-2007, 16:39   #4 (permalink)
theRemix
Battery Chicken
 
theRemix's Avatar
 
Join Date: Apr 2007
Location: Hawaii
Posts: 83
Send a message via AIM to theRemix Send a message via MSN to theRemix
this is how to 'just add actions to a button'

welcome to AS3 !

this way seems more complex, but in the long run, it saves tons of headaches... headaches like hunting for keyframes and buttons to click on just to find an erroneous code.

but in most simple cases. why not just stick with AS2 + timeline ?
  Reply With Quote
Old 24-11-2007, 16:56   #5 (permalink)
bazzle
Senior Member
 
bazzle's Avatar
 
Join Date: Aug 2007
Location: Derby uk
Posts: 468
Send a message via MSN to bazzle
I've got it working. I used this code.

Code:
stop(); forbutton.addEventListener( MouseEvent.CLICK, handleClick ); backbutton.addEventListener( MouseEvent.CLICK, handleClick ); function handleClick( pEvent:MouseEvent ) { if ( pEvent.target == forbutton ) { nextFrame(); } if ( pEvent.target == backbutton ) { prevFrame(); } }

Well this is the first time i've used flash since mx 2004. I can understand why it's easier to have all your script in one location than all over the place.

Just takes a bit of getting used to that's all.

I was close to switching it to AS2 but that would be the easy way out, it's always good to learn new stuff aswell.

Thanks for the help anyways.
  Reply With Quote
Old 26-11-2007, 02:31   #6 (permalink)
theRemix
Battery Chicken
 
theRemix's Avatar
 
Join Date: Apr 2007
Location: Hawaii
Posts: 83
Send a message via AIM to theRemix Send a message via MSN to theRemix
nice! i'm glad you chose to stick with AS3. you would really have to have tons of headaches in the past with AS2 before to truly appreciate the strict OOP enforced by AS3.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8