- Code: Select all
import flash.events.MouseEvent;
Then, you need to create a button on the field, or just use the draw function in Flash to create a button to the field..
(this code is for the drawing)
- Code: Select all
import flash.display.*;// import the button drawing stuff
function drawButton(event:Event){//run the function
var button1:MovieClip = new MovieClip();// create a new movieclip
button1.graphics.lineStyle(1);// sets line style
button1.graphics.beginFill(0xff0000);// fills the button with selected color
button1.graphics.drawCircle(200,200,50);// draws a circle at 200x, 200y, and with 50 scale
// there are other shapes (drawRectangle, drawTriangle) and can be used with the top code. :P
addChild(button1);// adds a child so all of the above could happen
button1.graphics.endFill();// ends fill
button1.addEventListener(MouseEvent.CLICK, buttonActive);// creates event listener
removeEventListener(Event.ENTER_FRAME, drawButton);// removes the Enter_Frame function
}
addEventListener(Event.ENTER_FRAME, drawButton);//Create the event
Now onto the button part..
Make an MC name button1 on the field, or use the above script.
Apply this to the frame:
- Code: Select all
addEventListener(Event.ENTER_FRAME, drawButton);// Creates the mouseevent
function buttonActive(e:MouseEvent){// runs the mouse event
//do stuff
}
Here's the full script:
- Code: Select all
stop();
import flash.events.MouseEvent;
import flash.display.*;// import the button drawing stuff
function drawButton(event:Event){//run the function
graphics.clear();
var button1:MovieClip = new MovieClip();// create a new movieclip
button1.graphics.lineStyle(1);// sets line style
button1.graphics.beginFill(0xff0000);// fills the button with selected color
button1.graphics.drawCircle(200,200,50);// draws a circle at 200x, 200y, and with 50 scale
// there are other shapes (drawRectangle, drawTriangle) and can be used with the top code. :P
addChild(button1);// adds a child so all of the above could happen
button1.graphics.endFill();// ends fill
button1.addEventListener(MouseEvent.CLICK, buttonActive);
removeEventListener(Event.ENTER_FRAME, drawButton);
}
addEventListener(Event.ENTER_FRAME, drawButton);//Create the event
function buttonActive(e:MouseEvent){
//do stuff
}
For more info on Drawing, go here.
For more info on Buttons, go here.
