Archive

Archive for the ‘flash’ Category

Making Flex scale when resized

May 2nd, 2011 Adam No comments

When applications made in Adobe Flash are resized, the default behavior is to scale the entire application. With Flex however, the default behavior is to resize the dimensions of the application container, without resizing any components. This is useful if you have designed a layout with relative positioning and sizing. But if you want your application to actually increase the size of each component, you will need to make a minor adjustment.

Add an event handler to the main application for addedToStage:

1
2
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="absolute" addedToStage="stretchHandler()">

And here’s the code for stretchHandler():

1
2
3
4
5
6
private function stretchHandler():void{
	stage.scaleMode = StageScaleMode.SHOW_ALL;
	stage.align = StageAlign.TOP;
	this.width = stage.stageWidth;
	this.height = stage.stageHeight;
}

The SWF on the left is the flex application at its normal dimensions (160×80). The SWF on the right is the exact same SWF file, but I embedded it using double dimensions (320×160).


(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)   (Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Categories: flash, flex Tags: , , , ,

Drawing A Sine Wave In Actionscript

August 7th, 2009 Adam 10 comments

Just a simple way to draw a sine wave with a specific amplitude and frequency. Use the sliders to adjust the values.
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Here’s the main function:

function drawWave(amp:int, freq:int):void{
	newSine.graphics.clear();
	newSine.graphics.lineStyle(2, 0xff0000, 0.4);
	newSine.graphics.moveTo(0, yaxis);
	for(var i:int=0; i&lt;=stage.stageWidth; i++){
		var ang:Number = 2 * Math.PI * freq * i/stage.stageWidth;
		newSine.graphics.lineTo(i, yaxis - amp*Math.sin(ang));
	}
}

(EDIT 8/14/09: In the SWF above, the sine wave is upside down. That’s because I had a typo when I wrote it. On line 7 of the code, I had typed “…yaxis + amp…” but it should be minus. The code above is correct, but the SWF hasn’t been updated)

Draw A Quick Stage Border in Flash

July 9th, 2009 Adam 1 comment

Here’s a quick way to automatically add a border to your flash stage without drawing an actual object and resizing it. I use this snippet alot.

1
2
3
4
var stagebox:Sprite = new Sprite();
stagebox.graphics.lineStyle(1, 0x000000, 1);
stagebox.graphics.drawRect(0, 0, stage.stageWidth-1, stage.stageHeight-1);
addChild(stagebox);