Posted By

Winkyboy on 11/07/08


Tagged

actionscript button 3 movieclip as3 onRelease onRollOver onRollOut MouseEvent


Versions (?)

Who likes this?

12 people have marked this snippet as a favorite

Bonky
teedy
meltmetal
catalin_ionescu
THEPWN3R
dada78
codyo
davidino1978
ssolen
svaye
tspitzr
adrianparr


AS3 MovieClip-as-a-Button Easy Function


 / Published in: ActionScript 3
 

Because making a button out of a movieclip in AS3 is ridiculously code-heavy, I wrote a simple function to set the needed values with only a couple of lines. You need the function placed within your code, after which you simply call it and then define the over/out/click functions for your movieclip.

  1. // Add any movieclip with (in this example) "my_mc" as the instance name.
  2.  
  3. makeButton(my_mc, my_mc_over, my_mc_out, my_mc_click);
  4.  
  5. function my_mc_over(evt:MouseEvent):void { trace("Rollover"); }
  6. function my_mc_out(evt:MouseEvent):void { trace("Rollout"); }
  7. function my_mc_click(evt:MouseEvent):void { trace("Clicked"); }
  8.  
  9. function makeButton(which_mc:MovieClip, overFunction:Function, outFunction:Function, clickFunction:Function):void {
  10. which_mc.buttonMode = true;
  11. which_mc.useHandCursor = true;
  12. which_mc.mouseChildren = false;
  13. which_mc.addEventListener(MouseEvent.MOUSE_OVER, overFunction);
  14. which_mc.addEventListener(MouseEvent.MOUSE_OUT, outFunction);
  15. which_mc.addEventListener(MouseEvent.CLICK, clickFunction);
  16. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: AndyJChew on April 6, 2011

I was able to create a button, but what are the next steps to link to another function? Once I click on the button, I want it to load another set of code that I have.

In brief, I need the button click to load an external XML data field in a dynamic text box. I have the code figured out to load the XML, but am still having difficulty loading the XML data in a dynamic text box. If you would be willing to take a look at the code that would be awesome.

Thank you.

You need to login to post a comment.