Came across an interesting utility related to key combinations in AS3
As3 Key combinations
0 comments | Labels: As3
As3 Character code (charcode) to Character
Came across a code which can convert character code to character.
this.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
function onKeyDown(vEvent:KeyboardEvent):void
{
trace(String.fromCharCode(vEvent.charCode));
}
0 comments | Labels: As3
Flex Image to Bitmap converter
Today I came across a problem where I required to convert an Image datatype to bitmap so that I can duplicate the dynamically loaded image.
//test_image is an object of image
var bitmap_data:BitmapData=Bitmap(test_image.content).bitmapData;
var bitmap:Bitmap = new Bitmap(bitmap_data);
Thats it the bitmap is ready :)
Converting and XMLList to XMLListCollection
// Say you have an XMLList object "xml_list"
//To convert it to XMLListCollection just do the below
var xmlListcol:XMLListCollection=new XMLListCollection(xmllist);
0 comments | Labels: As3
AS3 Vector
A vector elements should be of same data type.
var numVector:Vector.
numVector.push(2,17,6.6);
var sortedVector:Vector.
function sortNumbers(x:Number, y:Number):Number
{
// do the sorting here
}
Embed assets in flash cs4 through code
[Embed(source="/assets/flex4.png")]
var imageData:Class;
//Other property of embed
//[Embed(source="/assets/flex4.xml“, mimeType=“application/octet-stream”)]
var disObj:DisplayObject=new imageData();
addchild(disobj)
When you compile a dialogue will be displayed to select the flex sdk location.
The first time it will not work.
Compile it again to see it working.
0 comments | Labels: As3, cs4
As3 click and zoom to the mouse position
From quite a long time I used to face an issue when it comes to zooming a movie clip to the position where the mouse has been clicked and finally managed to find a decent solution.
Find a sample below:
The coding part:
image_mc.addEventListener(MouseEvent.MOUSE_UP, onImageClick);
function onImageClick(vEvent:MouseEvent):void
{
var cur_mx:Number=image_mc.mouseX;
var cur_my:Number=image_mc.mouseY;
image_mc.scaleX*=2;
image_mc.scaleY*=2;
image_mc.x=(cur_mx-(cur_mx*image_mc.scaleX));
image_mc.y=(cur_my-(cur_my*image_mc.scaleY));
}
0 comments | Labels: As3, zoom
AS3 Local to Global --- localToGlobal() function
Take the below scenairo where in the stage we have a main movieclip which contains two movieclips. A circle_mc and a rectangle_mc. I want to determine the stage position of the circle_mc.
To achieve this we have to use the localToGlobal method found in a movieclip object.
In the above scenario the code goes as below:
//The variable to store the target location required
var result_point:Point=new Point();
//a point object created for storing the current location of circle_mc
var circle_point:Point=new Point(map_mc.circle_mc.x, map_mc.circle_mc.y);
//using the localToGlobal method for calculating the current global position of circle.
result_point=map_mc.circle_mc.localToGlobal(circle_point);
0 comments | Labels: As3, localToGlobal


