Flash actionscript 3.0: August 2008

Creating a Button using Action Script 3.0

0

Posted by Sankar.G | Posted in | Posted on 12:40 AM

we can able to Create a Button in Flash using Action Script 3.0 with out do any design
code is Follows

AS3.0
Code:

var a:SimpleButton=new SimpleButton();
a.upState=up();
a.overState=over();
a.downState=down();
a.hitTestState=hit();
addChild(a);
a.addEventListener(MouseEvent.CLICK,fun);
function fun(e:Event)
{
trace("Checking");
}
function up()
{
var a1:Shape=new Shape();
a1.graphics.beginFill(0x0000ff);
a1.graphics.drawRect(0,0,175,125);
return(a1);
}
function down()
{
var a1:Shape=new Shape();
a1.graphics.beginFill(0xffff00);
a1.graphics.drawRect(0,0,175,125);
return(a1);
}
function over()
{
var a1:Shape=new Shape();
a1.graphics.beginFill(0xffff00);
a1.graphics.drawRect(0,0,175,125);
return(a1);
}
function hit()
{
var a1:Shape=new Shape();
a1.graphics.beginFill(0xffff00);
a1.graphics.drawRect(0,0,175,125);
return(a1);
}

we Have 4 state for button we want to define all the state in script to create a button

How to Create a Rectangle and Circle dynamically using Action Script 3.0

0

Posted by Sankar.G | Posted in | Posted on 11:42 PM

we can create a rectangle or cirlcle using Action Script 3.0

AS3.0
Code

var rect:Shape=new Shape();
rect.graphics.beginFill(0x00FFFF);
rect.graphics.drawRect(75,300,175,75);
addChild(rect);
var cir:Shape=new Shape();
cir.graphics.beginFill(0x00FFFF);
cir.graphics.drawCircle(0,0,40);
cir.x=40;
cir.y=40;
addChild(cir);
var tx:TextField=new TextField();
tx.type=TextFieldType.INPUT;
tx.text="sankar";
addChild(tx);


Syntax
drawRect(x,y,width,height);
drawCircle(x,y,radius);

you can able to change the text in to lower case,upper case etc using Actionscript 3.0

0

Posted by Sankar.G | Posted in | Posted on 12:29 AM

you can easily change the text in to lower case & upper case and find the length of a string in AS3.0 and you can find the desired word in which area

AS 3.0
Code:

b1_btn.addEventListener(MouseEvent.CLICK,fun);
b2_btn.addEventListener(MouseEvent.CLICK,fun1);
b3_btn.addEventListener(MouseEvent.CLICK,fun2);
b4_btn.addEventListener(MouseEvent.CLICK,fun3);
function fun(e:Event)
{
t1_txt.text=t1_txt.text.toUpperCase();
}
function fun1(e1:Event)
{
t1_txt.text=t1_txt.text.toLowerCase();
}
function fun2(e2:Event)
{
t2_txt.text=Number(t1_txt.text.length).toString();
}
function fun3(e3:Event)
{
t2_txt.text=Number(t1_txt.text.indexOf(t2_txt.text)).toString();
}

this is the code to became a text in to lower case,upper case and to find the length of a string and to find the index of the string using Action Script 3.0

if you want to get the color randomly using actionscritp 3.0

0

Posted by Sankar.G | Posted in | Posted on 12:45 PM

you can get the different color randomly using action script 3.0 & 2.0 also

AS 2.0:
code:
b1_btn.onPress=function()
{
var r:Number=random(256);
var b:Number=random(256);
var g:Number=random(256);
var box1:String=r.toString(16)+b.toString(16)+g.toString(16);
var box2:Number=parseInt(box1,16);
var box3:Color=new Color(movie_mc);
box3.setRGB(box2);
}

colors will always comes in alpha numeric & main color is red,green & blue so first we declare 3 variables and store the random number to that variable and we want to add the number and convert it to string using .tostring() funtion and base of the number is 16 because it is alphanumeric number and again we want to convert total string to a number using parseInt() function and store it in another variable now declare a new variable for the movie clip and set the color to the new variable
so if you press the button color will generate randomly

AS3.0
Code:

import flash.geom.ColorTransform;
b1_btn.addEventListener(MouseEvent.CLICK,fun);
var a:ColorTransform=movie_mc.transform.colorTransform;
function fun(e:Event)
{
var r:Number=Math.random()*256;
var b:Number=Math.random()*256;
var g:Number=Math.random()*256;
var total:String=r.toString(16)+b.toString(16)+g.toString(16);
var t1:Number=parseInt(total,16);
a.color=t1;
movie_mc.transform.colorTransform=a;
}

how to get the keyboard event in action script 3.0

0

Posted by Sankar.G | Posted in | Posted on 12:34 PM

you can able to get the ketboard event in action script 3.0
code:

parent.addEventListener(KeyboardEvent.KEY_DOWN.fun);
function fun(e:KeyboardEvent)
{
switch(e.keyCode)
{
case keyboard.RIGHT
movie_mc.x+=10;
break;
case keyboard.LEFT
movie_mc.x-=10;
break;
case keyboard.UP
movie_mc.y-=10;
break;
case keyboard.DOWN
movie_mc.y+=10;
break;
}
}
this is the way to get the keyboard Event using action script 3.0 movie_mc is a movie clip if you pressed the left button it will go to left side similarly to all side

how to get he System time in action script 3.0

3

Posted by Sankar.G | Posted in | Posted on 12:27 PM

you can get the system in action script 3.0 code is follows

code:
import flash.utils.*;
var ti:Timer=new Timer(1000);
ti.addEventListener(TimerEvent.TIMER,fun);
ti.start();
function fun(e:Event)
{
var a:Date=new Date();
if(a.hours>=13)
{
str = "PM"
}
else
{
str = "AM"
}
t1_txt.text=Number(a.getHours()).toString()+":"+Number(a.getMinutes()).toString()+":" +Number(a.getSeconds()).toString()+" "+str;
}

for this we want to import a library utils
and declare a variable t1 as a timer and 1000 is milliseconds timer will tick per second if you set 500 it will 2 times for a second and addeventlistener for that timer and start the timer
and we declare a variable a as date
and use gethour ,get minutes, get seconds is used to get the system times

below code is used to change the color to a movie clip on the run time

0

Posted by Sankar.G | Posted in | Posted on 12:11 PM

you can change the color of a movie clip at the run time

code:
import flash.geom.ColorTransform;
b1_btn.addEventListener(MouseEvent.CLICK,fun);
var a:colorTransform=movie_mc.transform.colortransform;
function fun(e:Event)
{
a.color=0xff0000;
movie_mc.transform.colortransform=a;
}

this is the way to change the color to an movie clip at the run time
we want to import the color transform library
& we want assign a variable for the color transform and apply movie clip to that variable
and apply some color to the variable a
and apply to the movie clip

tween action in action scrpti 3.0

1

Posted by Sankar.G | Posted in | Posted on 10:10 AM

we can do tween action in action script 3.0

code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
b1_btn.addEventListener(MouseEvent.CLICK,fun);
function fun(e:Event)
{
var a:Tween=new Tween(movie_mc,"rotation",Strong.easeOut,0,100,5,true);
}

before we want to tween we want to add some library in flash
so import tween & easing and declare a variable a and set Tween
movie_mc = movie clip name
rotation = which action we want to do (for ex):"x","alpha","y" we can put these functions
0=starting from zero axis
100=end to 100 axis
5=seconds to finish the rotation

read the X & Y axis of a mouse Pointer

0

Posted by Sankar.G | Posted in | Posted on 10:05 AM

if you want to get the X & Y axis of a mouse Pointer is Action script 3.0

code:
parent.addEventListener(Event.ENTER_FRAME,fun);
function fun(e:Event)
{
t1_txt.text=Number(mouseX).toString();
t2_txt.text=Number(mouseY).toString();
}

t1_txt & t2_txt = textboxes

click event in actionscript 3.0

0

Posted by Sankar.G | Posted in | Posted on 9:40 AM

if you want to do a click event in Action script 3.0 is different from 2.0 because you can able to write scripting to an object in 2.0 but you cant able to write a script to an object in 3.0 so we want to add a Listener in 3.0 code is follows

code:b1_btn.addEventListener(MouseEvent.CLICK,fun);
function fun(e:Event)
{
t1_txt.text="checking";
}

b1_btn = name of a button

if you want to move a object with mouse Pointer

0

Posted by Sankar.G | Posted in | Posted on 9:20 AM

If you want to move a object along with mouse pointer in Action script 3.0

code: parent.addEventListener(Event.ENTER_FRAME,fun);
function fun(e:Event)
{
movie_mc.startDrag(true);
}
flash.ui.Mouse.hide();
moive_mc.buttonMode=true;

this is the code to move a object along with mouse pointer
Explanitation:
parent is the screen in the actionscrpit 3.0 we want to mention parent for the screen
e is used to capture the ENTER_FRAME event & movie_mc in the name of a movie clip startDrag is used to move a movieclip along with mouse pointer & true is used to set correct position of the movieclip with mouse pointer X & Y axis and flash.ui.Mouse.hide() is used to hide the mouse pointer ui=userInterface devices buttonmode=true is used to change that movie clip to a mouse pointer

Import a .swf file in flash using actionscript

0

Posted by Sankar.G | Posted in | Posted on 12:31 PM

we can import a SWF file in flash using action script
In AS2.0
code: loadMovieNum("example.swf",0);

it is simple is as2.0 example.swf is a file name & 0 is the level of the file

In AS3.0

code: var ldr:Loader=new Loader();
var urlrequest:URLRequest=new URLRequest("example.swf")
ldr.load(urlrequest);
addChild(ldr);

In as3.0 Loader is used to load a file in flash
urlrequest is used to get the link of the file
addChild is used to add that file to the scene

Display a text in root text box using Actionscript 3.0

0

Posted by Sankar.G | Posted in | Posted on 11:46 PM

if you want to display a text in a root text box using Action script 3.0 use this code
textbox name in the root is t1_txt

code: root["t1_txt"].text=("Some Text");

if you want to display a number in root text box
var a:Number=10;
code: root["t1_txt"].text=Number(a).toString();

this is the way to display a text in the root text box using Action script 3.0

play head in which frame in flash

0

Posted by Sankar.G | Posted in | Posted on 1:10 PM

we can easily find play head in which frame using flash Action script for that Coding is follows
in AS2.0
Declare a variable
var fr=_currentframe;
display the fr in a textbox so you get the play head in which frame
in AS3.0
Declare a variable
var fr=currentFrame;
display the fr in a textbox so you get the play head in which frame

use timer concept to display frequently in both as2.0 & as3.0

load a variables from a text file to flash using AS3.0

0

Posted by Sankar.G | Posted in | Posted on 1:05 AM

load a variables from a text file to flash using AS3.0

Use this command : loadVariablesNum("test.txt", 0);
put any URL of text file insead of "test.txt" & 0 is level.