Hi,
In this i like to specify a simple button example in AS3.0.
Most people says we cant wright code in frame That is FALSE... We can... In this example i has written the code in the frame.
Step 1:
Create a button and place it in the stage... Give the instance name for it In my example i has specified as b1.
Step 2:
Go to the frame Now and add a event listener for that button.
like
Syntax:
<button>.addEventListener(<eventname>, <function_name>);
in our example
b1.addEventListener(MouseEvent.CLICK, button_click);
Step 3:
Write the code for function
Syntax
function <function_name>(<event object>:<event>):<return type>
{
//code for the function
}
in our example
function button_click(event:MouseEvent):void
{
trace("button is clicked");
}
where
button_click is the function Name
event is the object of the MouseEvent
MouseEvent is the event name.
You are done.
Run the file You made a button to work in AS3.0
Hear is the whole code...
function button_click(event:MouseEvent):void
{
trace("button is clicked");
}
b1.addEventListener(MouseEvent.CLICK, button_click);
Do u want to search anything in my site just try out the Google search Above next to the head.
Don't forget to leave a comment about this
No comments:
Post a Comment