Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-29-2012, 03:34 AM   #1
Registered User
Join Date: Jun 2012
Posts: 1
Default Efficient ActionScript 3.0

I use FlashDevelop 4.01 to write small ActionScript projects and have messed around with Mobile Adobe Air ActionScript 3.0 Apps. My question is for anyone who would like to answer, for them to share experience, or to help point me in a better direction. Here is a small code example of a Pong type ball bouncing around a 500 x 500 px screen.

Main.as -
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.display.StageScaleMode;
	import flash.display.StageAlign;
		pageTitle="AdvEngine - Flash Version 1.0")]
	public class Main extends Sprite 
		public static const WIDTH:uint = 500;
		public static const HEIGHT:uint = 500;
		private var ball:Ball = new Ball();
		public function Main():void 
			addEventListener(Event.ADDED_TO_STAGE, init);
			addEventListener(Event.ENTER_FRAME, update);
			addChild( ball );
		private function init(e:Event = null):void 
			removeEventListener(Event.ADDED_TO_STAGE, init);
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
		private function update(event:Event):void {

Ball.as -
	import flash.geom.Point;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	public class Ball extends Bitmap
		private var fp:Point 	= new Point(0, 0);
		private var dx:int 		= 5;
		private var dy:int		= 4;
		public function Ball() 
			super( new BitmapData( 10, 10, false, 0xffffff ) );
			cacheAsBitmap = true;
		public function update():void {
			fp.x = x + dx;
			fp.y = y + dy;
			// test horz boundaries
			if ( fp.x < 0 ) {
				fp.x = 0;
				dx *= -1;
			}else if ( Main.WIDTH < (fp.x + width) ) {
				fp.x = Main.WIDTH - width;
				dx *= -1;
			//test vert boundaries
			if ( fp.y < 0 ) {
				fp.y = 0;
				dy *= -1;
			}else if ( Main.HEIGHT < (fp.y + height) ) {
				fp.y = Main.HEIGHT - height;
				dy *= -1;
			x = fp.x;
			y = fp.y;

When the movie starts up it is choppy, for maybe the first 3 seconds, then it evens out, but continues to look choppy every now and then. Changing the frame rate to 60 instead of 30 makes it move without any choppy-ness on the computer, but for some reason my phone won't allow more than 35 - 40 fps. I thought using Bitmaps and cacheAsBitmap and cacheAsBitmapMatrix would be the best options I had for hitting that frame rate each time, but it still seems choppy. I thought 30 would be more than enough for solid fps.

- Is there a way to give more initial memory to the application? Would this help?

- Is there a way to push rendering to the GPU effectively instead of CPU ( I know the application.xml file in the mobile development has a tag <renderMode> which can be changed to gpu, but this has always slowed my application to 19 - 22 fps...

- Any ideas would be awesome. Or let me know if the above code runs perfectly smooth for you.

Thanks ahead of time
jfreynik is offline   Reply With Quote
Old 06-29-2012, 02:05 PM   #2
Senior Member
Join Date: Jan 2012
Posts: 608

The first thing to check is that you are using the latest AIR SDK version (which is 3.3 I think). If you're publishing using AIR 2.6 or below, you will get drastically reduced performance. The example you're describing shouldn't tax the phone that much.
dmb85 is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 07:36 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.