Simple actionscript 3.0 dynamic registration point

this is a very simple dynamic registration point in actionscript 3.0 using fl.motion.MatrixTransformer class. please refer the class for more useful features.


import fl.motion.MatrixTransformer;
import flash.display.Sprite
var box:Sprite;
box = new Sprite();
box.graphics.beginFill(0xFF0000);
box.graphics.drawRoundRect(0, 0, 100, 100, 5);
addChild(box);
box.x = (stage.stageWidth / 2);
box.y=stage.stageHeight/2;
var xPoint:uint = (box.width/2);
var yPoint:uint = (box.height / 2);
var mtrx:Matrix=box.transform.matrix;
MatrixTransformer.rotateAroundInternalPoint(mtrx, xPoint, yPoint, 40);
MatrixTransformer.setScaleX(mtrx,2)
box.transform.matrix=mtrx;

how to load external image with actionscript 3.0

This post is a simple example for actionscript 3.0 beginners. The bellow actionscript 3.0 code help you to understand how you can load an external image from a url. if any doubt or help please add a comment.


import flash.display.Loader;
import flash.net.URLRequest;
var url:String="http://www.sfubiz.ca/misa/image/flash.jpg"
var loader:Loader = new Loader();
loader.load(new URLRequest(url));
addChild(loader);

open URL with Querystring using actionscript 3.0

hi,

this post is not for actionscript masters this is only for those who just started playing with actionscript. this simple example demonstrate how to open a url with querystring HTTP GET method.


import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLVariables;

var url:String="http://anilmathewm.blogspot.com/search";
var variables:URLVariables = new URLVariables();
variables.q="actionscript";
var urlRequest:URLRequest = new URLRequest(url);
urlRequest.method="GET";
urlRequest.data=variables;
navigateToURL(urlRequest, "_blank");

flash actionscript 3.0 change color

bellow is a simple example to change the color of a DisplayObject(MovieClip,Button,Sprite) in flash actionscript 3.0.



// creates a red square
var square:Shape = new Shape();
//fill the square with blue color
square.graphics.beginFill(0x0000FF);
// drow the square
square.graphics.drawRect(0, 0, 150, 150);
//add the square to stage
addChild(square);
// calling the change color function
changeColor(square,0xff0000);

//changeColor function
function changeColor(o:DisplayObject,color:Number):void {
//create a new ColorTransform
var newColor:ColorTransform=new ColorTransform();
// set the color property
newColor.color=color;
//assign the new ColorTransform to target DisplayObject
o.transform.colorTransform=newColor;
}

Simple custom event example actionscript 3.0

This is a simple custom Event example I hope this will help actionscript 3.0 bingers to understand how event works in actionscript 3.0. In this example I just created a MouseDown event listener for stage mouse clicks. Clicking the stage will trigger the custom event.


const CUSTOM_EVENT:String='custom_event';
addEventListener(MouseEvent.CLICK,onMouseClick);
function onMouseClick(e:Event){
dispatchEvent(new Event(CUSTOM_EVENT));
}
addEventListener(CUSTOM_EVENT,onCustomevent)
function onCustomevent(e:Event){
display.text="Custom Event Called"
}

how to post data from actionscript 3.0 to php or asp.net sample

this a small example for sending and retrieving data from serverside scripts like php , asp.net or any thing


package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;

/**
* ...
* @author Anil Mathew
*/
public class Main extends Sprite
{
public var loader:URLLoader; //url loader
private var _url:String // the url string
private var _req:URLRequest; // url request
public var _vars:URLVariables; // url variables
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
_url = "http://www.yahoo.com/";// url where we need to post the data
_req = new URLRequest(_url);// url request instance
_req.method = URLRequestMethod.POST ; // metheod to use for the request
_vars = new URLVariables();// url variables
_vars.name = "Myname"; // sending name
_vars.age = 21; //sending age
loader = new URLLoader(); //loader instance
loader.load(_req); //loading request
loader.addEventListener(Event.COMPLETE, completeHandler);// event handler for complete event


}

private function completeHandler(event:Event):void {
trace(event.target.data); // returned data
}


}

}

how to access maintimeline functions and variables from a nested movieclip in as3

This is the biggest problem for actionscript coders those who migrate from actionscript 2.0 and actionscript 1.0 to actionscript 3.0. In as1,as2 we can access the main timeline functions and variables from a nested movieclips just using _root.varName or _root.functionName, But in as3 we cant access the maintimline variables and functions this way.following is a sample code to access the maintimeline variable and functions from a nested movieclip.

MovieClip(root).functionName();
Or
MovieClip(root).varName

_global variable in actionscript 3.0

here is a simple class that help global vars in actionscript 3.0

package {
public class globals {
public static var vals:Object = new Object();
}
}

now you can access the globals.vals any where from your movie.

globals.vals.red = 0xFF0000;
trace(glo.bal.red);

cs4 FileReference.save example

this is a simple example of new feature in flash cs4 FileReference.save(). in this example i just create an html file using the rich text editor from http://mobilewish.com/applications/as3texteditor/. and save it using FileReference.save() to local file system . download rich text editor

Source File:http://anilmathew.info/flash/filerefer_example.fla
code sample


import flash.net.FileReference;


tt.input_txt=abc;
tt.scroller=scroller;
abc.addEventListener(MouseEvent.MOUSE_UP, tt.handleClick);
generate_btn.addEventListener( MouseEvent.CLICK, generateTEXT );

function generateTEXT( e:MouseEvent ) {

var texT:String=abc.htmlText;
var file:FileReference = new FileReference();
file.save(texT,"myfile.html");


}





What is bubbles property in Actionscript 3.0 Event ?

When an event occurs, it moves through the three phases of the event flow: the capture phase, which flows from the top of the display list hierarchy to the node just before the target node; the target phase, which comprises the target node; and the bubbling phase, which flows from the node subsequent to the target node back up the display list hierarchy.

AS3 button click events vs As2 button click events example

this is a simple button tutorials for As3 beginners.

A simple As2 buttonClick

on(press){

trace("Clicked");

}


Or

[button].onPress=function(){

trace("clicked");

}

In as3

simple one

[button].addEventListener(MouseEvent.CLICK,function(){trace("clicked")});

or

function buttonClick(evt:MouseEvent) {

trace("clicked");

}

[button].addEventListener(MouseEvent.CLICK,buttonClick);


so what is in "evt:MouseEvent"?. just try this one

function buttonClick(evt:MouseEvent) {

trace(evt.target.name);

}

[button].addEventListener(MouseEvent.CLICK,buttonClick);

This event has the following properties:

Property Value
bubbles true
buttonDown true if the primary mouse button is pressed; false otherwise.
cancelable false; there is no default behavior to cancel.
ctrlKey true if the Control key is active; false if it is inactive.
currentTarget The object that is actively processing the Event object with an event listener.
localX The horizontal coordinate at which the event occurred relative to the containing sprite.
localY The vertical coordinate at which the event occurred relative to the containing sprite.
shiftKey true if the Shift key is active; false if it is inactive.
stageX The horizontal coordinate at which the event occurred in global stage coordinates.
stageY The vertical coordinate at which the event occurred in global stage coordinates.
target The InteractiveObject instance under the pointing device. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.


PHP developer Cochin |PHP developer Kerala | PHP developer India | Flash developer/programmer Cochin | Flash developer/programmer Kerala | Flash developer/programmer India | web programmer kerala |web programmer Cochin |web programmer India |web developer kerala |Web developer Cochin | Kerala PHP | PHP freelancer| flash actionscript freelancer