Home » Archive

Articles in the Flash CS4 Category

ActionScript 3.0, Flash CS4, Flash CS5 »

[17 Sep 2012 | No Comment | ]

We may want to supply different number sequence may be randomized to our code in order to behave different in situation. Since we dont have array shuffle function in as3. We have to write our code to achieve the effect.
So I have given different ways of acheiving randomized array in as3. The most important is without using looping statement.
Below is examples of functions which randomizes the order of the elements in the array.
Randomize an array  as3 without looping statement
var rawArr:Array = [“1″,”2″,”3″,”4″,”5″];
trace(randomizeArray(rawArr));
function randomizeArray(myArray:Array):Array
{
myArray.sort(function(){ return Math.random()-0.5; });
return myArray;
}
Randomize an array …

ActionScript 2.0, ActionScript 3.0, Flash CS4, Flash CS5, Flex »

[12 Mar 2011 | 2 Comments | ]

Maths and ActionScript together makes nice Flash effects like particles effect and Flash games that we play daily. Today, lets take a
look at ActionScripting in Maths.
Distance between two points:
Pass the two points as arguments to get the resulting distance between two points.
public function distance(p1:Point, p2:Point):Number {
var dx:Number = p2.x-p1.x;
var dy:Number = p2.y-p1.y;

return Math.sqrt(dx*dx + dy*dy);
}
Angle/Rotation between two points:
Need to pass the four arguments to get the Angle, (X1,Y1) pointA and (X2,Y2) pointB.
function getAngle (x1:Number, y1:Number, x2:Number, y2:Number):Number
{
var dx:Number = x2 – x1;

ActionScript 3.0, AIR, Flash CS4, Flash CS5 »

[1 Mar 2011 | 6 Comments | ]

How to do a String to character array conversion using Flash actionscript, as3. The String class has a neat method for doing this, split().
In the code example below the String is converted to a char array and each element of the array is printed out.
var str:String = “DesignScripting.com – A Flash ActionScript resource.”

trace(str.split(”));

// Output : D,e,s,i,g,n,S,c,r,i,p,t,i,n,g,.,c,o,m, ,-, ,A, ,F,l,a,s,h, ,A,c,t,i,o,n,S,c,r,i,p,t, ,r,e,s,o,u,r,c,e,.
Note:
The output of str.split(”) is an Array.
Assign the output to and empty Array and lets see the output and try to access the character array by its index of 0

var …

ActionScript 3.0, AIR, Android, Flash CS4, Flash CS5 »

[28 Feb 2011 | One Comment | ]

TinyUrl is a url shortener such as bit.ly or TinyUrl to share your favorite blog posts and links on the network.
Actionscript – as3 version of TinyUrl creation:
import flash.events.*
import flash.net.*;
import flash.net.URLVariables;

var variables:URLVariables = new URLVariables();
variables.url = String(“http://www.designscripting.com”);
sendAndLoad(“http://tinyurl.com/api-create.php”, variables)

function sendAndLoad( url:String, _vars:URLVariables ):void {

var request:URLRequest = new URLRequest(url);
var _urlloader:URLLoader = new URLLoader();
_urlloader.dataFormat = URLLoaderDataFormat.TEXT;
request.data = _vars;
request.method = URLRequestMethod.POST;
_urlloader.addEventListener(Event.COMPLETE, handleComplete);
_urlloader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
_urlloader.load(request);

}
function handleComplete(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace(“TinyURL: ” + loader.data);
}
function onIOError(event:IOErrorEvent):void {
trace(“Error loading URL.”);
}
In the above Actionscript code change the URL string and run the application to generate the shortened Url.
variables.url = String(“http://www.designscripting.com”);
We are …

ActionScript 3.0, Android, Flash CS4, Flash CS5 »

[25 Feb 2011 | 3 Comments | ]

On tutorial Request of “Dynamic Font embedding in as3″ I am writing this tutorial of how to embed fonts in Flash CS5 using actionscript 3.0 ( as3 ).
Difficulty:
Beginner to Intermediate
In this article we are going to study how to runtime font embed in actionscript 3. In this article we are going to see

Add Font in library and linkage
How to create textfield in runtime
How to embed fonts in runtime using as3

Add Font in library and linkage:
Step 1: Open New document in Adobe Flash CS5
Step 2: Open Library from Window Menu -> …