Pages

Wednesday, May 2, 2012

Combo box example in AS3




Step:1
Create the data list out for Combo box.
Here we use Flash Combo box component.


import fl.data.DataProvider;
var dp:DataProvider=new DataProvider();
level.dataProvider=dp
var it:Array=new Array()
it=["Kumaresh","Aarthi","Vasan","Sai","Sangari","Hari","Vignesh","Keerthi","Chitra","Aarchana"];
dp.addItem({label: "Select a Name"});
for(var i:Number=0;i<it.length;i++)
{
dp.addItem({label:it[i]});
}

Step:2
here level is a Combo box instance name. and name_txt is a text box for display selected name after change combo box.

level.addEventListener(Event.CHANGE, changeHandler);
function changeHandler(event:Event):void
{
if(level.selectedIndex!=0)
  name_txt.text=level.selectedLabel;
else
name_txt.text="";
}




Thank you


...CHeeRS...





                                     SourceFile

How to use mouse wheel for Zoom IN Zoom OUT in Actionscript3.0





Here we look at Mouse Scroll Zoom In and Zoom Out in AS3.

/** add Mouse Wheel event for stage **/

stage.addEventListener(MouseEvent.MOUSE_WHEEL, Zoom);

/** ma_mc is the mountain image MovieClip **/
function Zoom(e:MouseEvent):void
{       
var mod:Number = 20;
ma_mc.scaleX += e.delta / mod;
        ma_mc.scaleY += e.delta / mod;
        ma_mc.x = ((2 * mouseX) - (2 * (e.localX * ma_mc.scaleX))) / 2;
ma_mc.y = ((2 * mouseY) - (2 * (e.localY * ma_mc.scaleY))) / 2;
}


...CHeeRS...





SourceFile

Tuesday, May 1, 2012

Ball Movement With Multi Keyboard Event in ActionScript3.0




How to Identify Multi Key down in keyboard event?

here is Example:-

private var activeKeys:Object=new Object();

stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDownFunction);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUpFunction);

private function onKeyDownFunction(event:KeyboardEvent):void
{
activeKeys[event.keyCode] = true;
}

private function onKeyUpFunction(event:KeyboardEvent): void
{
activeKeys[event.keyCode] = false;
}

now to easily find which key buttons are down in your Keyboard from activeKeys object.

this is the step for find key down:

activeKeys[Keyboard.LEFT] == true means left key arrow button is still key down.

activeKeys[Keyboard.LEFT]== false means left key arrow button is still key up. 


and now How to move the ball with use multi key event?

private var speedX:Number = 0;
private var speedY:Number = 0;
private var fricrion:Number = 0.95;
private var power:Number = 5;

ball_mc.addEventListener(Event.ENTER_FRAME, onRunningFunction);
/** here ball_mc is a MovieClip **/

private function onRunningFunction(event:Event):void
{
if (activeKeyContainer[Keyboard.LEFT])
speedX = -power;
if (activeKeyContainer[Keyboard.RIGHT])
speedX = power;
if (activeKeyContainer[Keyboard.UP])
speedY = -power;
if (activeKeyContainer[Keyboard.DOWN])
speedY = power;
/** friction apply for reduce the speed slowly **/
speedX *= fricrion;
speedY *= fricrion;
/**--------------------------------------------**/
ball_mc.x += speedX;
ball_mc.y += speedY;
/** avoid ball out of stage **/
if (ball_mc.x < ball_mc.width/2)
ball_mc.x = ball_mc.width / 2;
if (ball_mc.x > stage.stageWidth - ball_mc.width / 2 )
ball_mc.x = stage.stageWidth-ball_mc.width/2;
if (ball_mc.y < ball_mc.height / 2 )
ball_mc.y = ball_mc.height/2;
if (ball_mc.y > stage.stageHeight - ball_mc.height / 2)
ball_mc.y = stage.stageHeight-ball_mc.height/2;
/**------------------------**/
}

simply try it your system friends.

...CHeeRS...




click above demo and press up,down,left,right key board event.


         SourceFile

Sunday, April 29, 2012

How to upload local disk IMAGE in FLASH AS3




Here we have use to FileRefrence Class.

What is mean FileRefrence?
       
         A FileReference object represents a data file on a client or server machine. The methods of the FileReference class let your application load and save data files locally, and transfer file data to and from remote servers.


Example:-

package 
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.events.Event;

/**
* ...
* @author KUMARESH NRV
*/
public class Upload extends Sprite  
{
 
private var fileRef:FileReference;
private var imageTypes:FileFilter;

/** constructor **/
public function Upload():void
{
init();
}

/**
* @details init function
*/
private function init():void
{
fileRef = new FileReference();
fileRef.addEventListener(Event.SELECT, onSelectFile);
fileRef.addEventListener(Event.COMPLETE, onLoadComplete);
imageTypes = new FileFilter("Images (*.jpg, *.png)", "*.jpg;*.png");
upload_mc.addEventListener(MouseEvent.CLICK, onShowUploadPage);
}
 
/**
* @details file reference page display
* @param event
*/
private function onShowUploadPage(event:MouseEvent):void
{
fileRef.browse([imageTypes]);
}
 
/**
* @details on select image file
* @param event
*/
private function onSelectFile(event:Event):void
{
fileRef.load();
}
 
/**
* @details on image load complete
* @param event
*/
private function onLoadComplete(event:Event):void
{
imageStage_mc.loadBytes(fileRef.data);
}
}

}



here FileFilter using for filter to image files (image,text,doc,etc.)
and then imageStage_mc is UILoader Component.


try it Friends.

...CHeeRS...







Saturday, April 28, 2012

How to get MovieClip X and Y position from child MovieClip to parent main MovieClip in AS3


Step 1: Change Movie clip to Object.
example:- Here have c_mc is child of b_mc and b_mc is a child of a_mc.

now we will find c_mc x and y postion in main stage

var obj:Object=new Object();
obj=a_mc.b_mc.c_mc;

Step 2: Get x and y position using with localToGlobal method.
var poi:Point=new Point(obj.x,obj.y);
poi=obj.parent.localToGlobal(poi);

poi.x and poi.y are c_mc movieclip x,y positions.
Thank you Friends 
...CHeeRS...