Pages

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...