This Blog contains About Action script 3.0 Variables, Data types, Access specifies, Keywords, Operators, Conditional statements, Control statements, Arrays (Indexed, Associative, Multidimensional, Cloning), Functions, Symbols, Movie clips (Transformation point, Registration point, Loading images), Buttons, Events (Key board, Mouse, Timer, XML)Pre- defined function :- Random, Hit test object, Drag and drop, Sort, Loader, Tween,URL Loader, Video components, Audio Components, Sound Channel.
Wednesday, 19 December 2012
gradient background using as2 code
wSize = Stage.width;
hSize = Stage.height;
fillType = "linear";
colors = [0xFF0000, 0xFFFF00];
alphas = [100, 100];
ratios = [0, 255];
matrix = {matrixType:"box", x:0, y:0, w:wSize, h:hSize, r:90/180*Math.PI};
_root.lineStyle(1, 0xFFFFFF, 0);
_root.beginGradientFill(fillType, colors, alphas, ratios, matrix);
_root.lineTo(wSize, 0);
_root.lineTo(wSize, hSize);
_root.lineTo(0, hSize);
_root.lineTo(0, 0);
_root.endFill();
out put looks like :-
gradient background using as3 code
var rect:Shape=new Shape();
this.addChild(rect);
rect.x = 0;
rect.y = 0;
var rectWidth:Number = 640;
var rectHeight:Number = 480;
var mat:Matrix;
var colors:Array;
var alphas:Array;
var ratios:Array;
mat=new Matrix();
colors = [0x000000,0x006699];
alphas = [1,1];
ratios = [0,255];
mat.createGradientBox(rectWidth,rectHeight,toRad(-90));
rect.graphics.lineStyle();
rect.graphics.beginGradientFill(GradientType.LINEAR,colors,alphas,ratios,mat);
rect.graphics.drawRect(0,0,rectWidth,rectHeight);
rect.graphics.endFill();
function toRad(a:Number):Number
{
return a*Math.PI/180;
}
Out put looks like :-
glow filter effect on mouse-over in as3
1. create a movieclip with the instance name of 'robot'
import flash.filters.*;
//This creates a new GlowFilter that we can then assign to a movieclip on the stage
var robotGlow:GlowFilter = new GlowFilter();
//The color of the GlowFilter
robotGlow.color = 0x138613;
//The size of the filter on the x-axis
robotGlow.blurX = 50;
//The size of the filter on the y-axis, these don't have to be the same
robotGlow.blurY = 50;
//Setting the alpha of our filter to zero to start off with
robotGlow.alpha = 0;
//Assigning the GlowFilter to the robot movieclip
robot.filters = [robotGlow];
//This will tell our filter when to turn on and off
var glow:Boolean = false;
//Our listeners
addEventListener(Event.ENTER_FRAME, increaseGlow);
//This function sets glow to true which turns on the glow when the mouse cursor is over our movieclip
function addGlow(e:MouseEvent):void
{
robotGlow.alpha = 100;
glow = true;
}
//This turns off the glow when the mouse cursor leaves the movieclip
function removeGlow(e:MouseEvent):void
{
robotGlow.alpha =0;
glow = false;
}
//This checks the status of glow and turns on and off our glow
function increaseGlow(e:Event):void
{
robot.addEventListener(MouseEvent.MOUSE_OVER, addGlow);
robot.addEventListener(MouseEvent.MOUSE_OUT, removeGlow);
robot.filters = [robotGlow];
}
Out put looks like :-
import flash.filters.*;
//This creates a new GlowFilter that we can then assign to a movieclip on the stage
var robotGlow:GlowFilter = new GlowFilter();
//The color of the GlowFilter
robotGlow.color = 0x138613;
//The size of the filter on the x-axis
robotGlow.blurX = 50;
//The size of the filter on the y-axis, these don't have to be the same
robotGlow.blurY = 50;
//Setting the alpha of our filter to zero to start off with
robotGlow.alpha = 0;
//Assigning the GlowFilter to the robot movieclip
robot.filters = [robotGlow];
//This will tell our filter when to turn on and off
var glow:Boolean = false;
//Our listeners
addEventListener(Event.ENTER_FRAME, increaseGlow);
//This function sets glow to true which turns on the glow when the mouse cursor is over our movieclip
function addGlow(e:MouseEvent):void
{
robotGlow.alpha = 100;
glow = true;
}
//This turns off the glow when the mouse cursor leaves the movieclip
function removeGlow(e:MouseEvent):void
{
robotGlow.alpha =0;
glow = false;
}
//This checks the status of glow and turns on and off our glow
function increaseGlow(e:Event):void
{
robot.addEventListener(MouseEvent.MOUSE_OVER, addGlow);
robot.addEventListener(MouseEvent.MOUSE_OUT, removeGlow);
robot.filters = [robotGlow];
}
Out put looks like :-
Drop down list in actionscript3 using transitions effects
//Import the required classes
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
//Turn on buttonMode for our movieclips
button_mc.buttonMode=true;
dropdown_mc.buttonMode=true;
//Add the dropDown Event Listener
button_mc.addEventListener(MouseEvent.CLICK, dropDown);
//initial dropDown function to animate on our dropdown movieclip into the mask
function dropDown(e:MouseEvent):void
{
var enterTween:Tween;
enterTween = new Tween(dropdown_mc, "y", Regular.easeOut, dropdown_mc.y, 177, 30, false);
enterTween.addEventListener(TweenEvent.MOTION_FINISH, dropUpEventListener);
}
//This function is called on after the dropdown animation is finished
function dropUpEventListener(e:TweenEvent):void
{
button_mc.removeEventListener(MouseEvent.CLICK, dropDown); //remove event listener to dropDown function
button_mc.addEventListener(MouseEvent.CLICK, dropUp); // add event listener for dropUp function
}
//Drop up function tweens out our dropdown movieclip from the mask
function dropUp(e:Event):void
{
var enterTween:Tween;
enterTween = new Tween(dropdown_mc, "y", Regular.easeOut, dropdown_mc.y, -8, 30, false);
enterTween.addEventListener(TweenEvent.MOTION_FINISH, dropDownEventListener);
}
//Function does the exact opposite of the dropUpEventListener
function dropDownEventListener(e:TweenEvent):void
{
button_mc.removeEventListener(MouseEvent.CLICK, dropUp);
button_mc.addEventListener(MouseEvent.CLICK, dropDown);
}
How to convert movie clip to bitmap in action script 3.0
var bitmapInfo:BitmapData = new BitmapData(myClip.width,myClip.height);
bitmapInfo.draw(myClip);
var bm:Bitmap = new Bitmap(bitmapInfo);
addChild(bm);
Friday, 7 December 2012
load as2 swf in as3
SWF files written in ActionScript 1.0 or 2.0 cannot load SWF files written in ActionScript 3.0.
"0
1
ArgumentError: Error #2180: It is illegal to move AVM1 content (AS1 or AS2) to a different part of the displayList when it has been loaded into AVM2 (AS3) content.
at flash.display::DisplayObjectContainer/addChild()
at swfloading_fla::MainTimeline/onCompleteHandler()
"
"0
1
ArgumentError: Error #2180: It is illegal to move AVM1 content (AS1 or AS2) to a different part of the displayList when it has been loaded into AVM2 (AS3) content.
at flash.display::DisplayObjectContainer/addChild()
at swfloading_fla::MainTimeline/onCompleteHandler()
"
How to load .swf file using action script 3.0
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
function startLoad() {
var mLoader:Loader = new Loader();
var mRequest:URLRequest=new URLRequest("SampleSWFFile.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event) {
addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent) {
var percent:Number=mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();
Subscribe to:
Posts (Atom)