First, I would like to thank everyone for contributing to this community. I regularly troll the forums for ideas and this will be my first post/request for help. Hopefully my idea is a sound one and will be able to help others once I figure it out.
I want to create a class, or classes, that will allow my designers, working in Flash Pro CS5, to call a Movie Clip from their library to be used as a button on the stage. In a perfect world they would do this with one line of code, setting the dynamic label text, the X and Y position, and setting the URL for the onClick function such as below:
homeBtn.SetBtn("Home", 10, 10, "www.website.com");
Below is the class code I have written:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.navigateToURL;
public class SetBtn extends MovieClip
{
public function SetBtn(btnLabel:String,btnX:Number,btnY:Number,btnURL:String)
{
//sets the parameters in the constructor function
btnLabel_txt.text = btnLabel;
this.x = btnX;
this.y = btnY;
this.buttonMode = true;
//add the event listeners for the mouse events
this.addEventListener(MouseEvent.CLICK,clickHandler);
this.addEventListener(MouseEvent.ROLL_OUT,rollOutHandler);
this.addEventListener(MouseEvent.ROLL_OVER,rollOverHandler);
}
//these are the functions for the mouseEvents
private function rollOverHandler(e:MouseEvent):void
{
trace("over is working");
e.target.gotoAndPlay("Over");
}
private function rollOutHandler(e:MouseEvent):void
{
trace("out is working");
e.target.gotoAndPlay("Out");
}
private function clickHandler(e:MouseEvent):void
{
trace("Click is working");
try
{
navigateToURL(new URLRequest(btnURL),"_blank");
}
catch (e:Error)
{
trace("Error occurred!");
}
}
}
}
What I need is some direction on how to best implement this idea. How do I direct it to what MC I want in the Library? I am guessing it would be another parameter of the method call, but how would that work? I would like them to be able to use the code on any MC design they create. Any thoughts or ideas would be greatly appreciated.
Thanks
-Gil