Archive for May, 2010:
Stage resize in AS3
In this tutorial, you’ll learn how to listen for and handle the resizing of the browser.
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
function resizeHandler(e:Event):void
{
mc_object.width = stage.stageWidth
mc_object.height = stage.stageWidth
trace(stage.stageWidth)
trace(stage.stageWidth)
}
//The Event.RESIZE is an event that is triggered each time the browser or Flash Player window is resized, it must be registered with the stage.
stage.addEventListener(Event.RESIZE, resizeHandler);
stage.scaleMode = StageScaleMode.NO_SCALE;
function resizeHandler(e:Event):void
{
mc_object.width = stage.stageWidth
mc_object.height = stage.stageWidth
trace(stage.stageWidth)
trace(stage.stageWidth)
}
//The Event.RESIZE is an event that is triggered each time the browser or Flash Player window is resized, it must be registered with the stage.
stage.addEventListener(Event.RESIZE, resizeHandler);
0 Comments
AS3 resize a movieClip and constrain proportions
Below is a very good tutorial to resize movieClip with aspect radio maintain.
//The resizing function
// parameters
// required: mc = the movieClip to resize
// required: maxW = either the size of the box to resize to, or just the maximum desired width
// optional: maxH = if desired resize area is not a square, the maximum desired height. default is to match to maxW (so if you want to resize to 200x200, just send 200 once)
// optional: constrainProportions = boolean to determine if you want to constrain proportions or skew image. default true.
function resizeMe(mc:MovieClip, maxW:Number, maxH:Number=0, constrainProportions:Boolean=true):void{
maxH = maxH == 0 ? maxW : maxH;
mc.width = maxW;
mc.height = maxH;
if (constrainProportions) {
mc.scaleX < mc.scaleY ? mc.scaleY = mc.scaleX : mc.scaleX = mc.scaleY;
}
}
resizeMe(image, stage.stageWidth)
// parameters
// required: mc = the movieClip to resize
// required: maxW = either the size of the box to resize to, or just the maximum desired width
// optional: maxH = if desired resize area is not a square, the maximum desired height. default is to match to maxW (so if you want to resize to 200x200, just send 200 once)
// optional: constrainProportions = boolean to determine if you want to constrain proportions or skew image. default true.
function resizeMe(mc:MovieClip, maxW:Number, maxH:Number=0, constrainProportions:Boolean=true):void{
maxH = maxH == 0 ? maxW : maxH;
mc.width = maxW;
mc.height = maxH;
if (constrainProportions) {
mc.scaleX < mc.scaleY ? mc.scaleY = mc.scaleX : mc.scaleX = mc.scaleY;
}
}
resizeMe(image, stage.stageWidth)
Sending data using Post
This simple example shows how to use the URLLoader and URLRequest class in actionscript 3 to post data to a server.
var dataRequestURL:String = "index.php";
var dataLoader:URLLoader = new URLLoader();
var dataVars:URLVariables = new URLVariables();
var dataRequest:URLRequest = new URLRequest(dataRequestURL);
//Prepare variables
dataVars.name = "yourname";
dataVars.password = "yourpassword";
trace("Sending Data:");
for (var i:String in dataVars) {
trace( " " + i + " = " + dataVars[i] );
}
//Prepare data to be send over
dataRequest.method = URLRequestMethod.POST;
dataRequest.data = dataVars;
//Prepare sending of data
dataLoader.addEventListener(Event.COMPLETE, onDataLoad);
dataLoader.addEventListener(IOErrorEvent.IO_ERROR, publicErrorHandler7);
dataLoader.load(dataRequest);
function publicErrorHandler7(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
function onDataLoad(e:Event) {
var xml:XML;
xml = new XML(e.target.data);
trace(xml)
}
var dataLoader:URLLoader = new URLLoader();
var dataVars:URLVariables = new URLVariables();
var dataRequest:URLRequest = new URLRequest(dataRequestURL);
//Prepare variables
dataVars.name = "yourname";
dataVars.password = "yourpassword";
trace("Sending Data:");
for (var i:String in dataVars) {
trace( " " + i + " = " + dataVars[i] );
}
//Prepare data to be send over
dataRequest.method = URLRequestMethod.POST;
dataRequest.data = dataVars;
//Prepare sending of data
dataLoader.addEventListener(Event.COMPLETE, onDataLoad);
dataLoader.addEventListener(IOErrorEvent.IO_ERROR, publicErrorHandler7);
dataLoader.load(dataRequest);
function publicErrorHandler7(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
function onDataLoad(e:Event) {
var xml:XML;
xml = new XML(e.target.data);
trace(xml)
}
