5005: Unknown error optimizing byte code and “You cannot debug this SWF because it does not contain ActionScript”

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

So it would turn out that flash CS4 cannot handle large projects out of the box. It took me a while to find the solution that is why I am republishing. This fix was originally posted on negush Their post was originally about fixing the 5005: Unknown error optimizing byte code.  But what I found out later after swapping to a new macihine is that the fix below also fixes the “You cannot debug this SWF because it does not contain ActionScript”. What I think happens is the compiler runs out of memory in a big project and instead of erroring shows you the stuipid non helpful error.

But the fix below should solve the two issues (5005: Unknown error optimizing byte code  and You cannot debug this SWF because it does not contain ActionScript)

Fix - windows (sorry i dont know how to change environmental vars on mac)

my computer -> properties -> advanced -> environment vars -> then make a new var like this

JAVA_TOOL_OPTIONS

and its value

-Xmx128M     or       -Xmx256M

Another solution on the web is to delete the .aso files generated by Flash (Control -> Delete ASO Files) .

If someone knows how to set the fix on a mac can they please post a comment

Random Number within a range

This is a simple function that returns a random value within a range.

function randomNumber(rangeMax:int = 1, rangeMin:int = 0):int
{
	return Math.round(Math.random() * (rangeMax - rangeMin) + rangeMin);
}
 
 trace(randomNumber(13, -3)); // Returns a random number between -3 and 13.
 trace(randomNumber(50));  // Returns a random number between 0 and 50.
 trace(randomNumber()); // Returns 0 or 1 as random number.


Globals in AS3

So as we all know in AS3 there is not such thing as _root or globals.

But sometimes you just really want and need global vars, so what to do.

Well never fear Paulius Uza has created a global class.

Global Object is a Singleton that lets you store dynamic variables in a globally accessible location within your AS3 application. This enables developers to accomplish things like self registering visual components, global events and event listeners.

I have used this class in many projects and found it great. Using it is simple see the example below

package  {
	import flash.display.*;
	import lt.uza.utils.*;
	public class Test extends Sprite
	{
		private var global:Global = Global.getInstance();
		private var testSprite:Sprite = new Sprite();
		public function Test(){
			//setting variables is easy, global object accepts any name / value pair, even functions
			global.stage = this.stage;
			global.testA = "a"
			global.testB = testSprite;
					global.testF = test;
					//getting variables is easy too
					trace(global.testA);
					this.addChild(testB);
					//as easy as calling a globally stored function
					global.testF();
		}
		private function test():void {
				trace("this is a global test");
		}
	}
}

Click here to find out more and download the class


Flash Meta

This code/meta data allows you to change settings in the player.

[SWF width="#"
height="#"
widthPercent="#"
heightPercent="#"
scriptRecursionLimit="#"
scriptTimeLimit="#"
frameRate="#"
backgroundColor="#"
pageTitle="<String>"]

Finding Memory Leaks - Memory Usage Guage

Following on from my previous post about memory leaks I thought I would show you the code I use for spotting for memory leaks at runtime.

See below

import flash.events.*;
import flash.system.System;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.utils.Timer;
 
var tf:TextField = new TextField();
tf.border = true;
tf.textColor = 0x333333
tf.background = true
tf.autoSize = TextFieldAutoSize.LEFT;
addChild(tf) 
 
initTimer();
 
function initTimer():void {
	var myTimer:Timer = new Timer(1000, 0);
	myTimer.addEventListener("timer", timerHandler1);
	myTimer.start();
}
 
function timerHandler1(event:TimerEvent):void {
	tf.text = String(Math.round(flash.system.System.totalMemory /1000 /1000)) + " MB \n " + String(flash.system.System.totalMemory) + " Bytes";
}

Memory Managment - Memory Leak

Now one of the biggest features of as3 is the management of memory within flash and flex.

In my experience event listeners are the source of about 95 percent of all memory leaks. This is because event listeners are often forgotten by developers, which normally results in the listener never being removed from memory.

This is where weakly referenced event listeners come into their own.

Weakly references to objects that are not counted by the Garbage Collector in determining an object’s availability for collection. So if you forget to remove the listener you wont stop the Garbage Collector’s ability to collect the object and freeing your memory. Yay…

So from that stand point alone I suggest that you use Weakly reference Event listeners as standard practice.

To make your event listener weakly then just set the fith param in the addEventListner to true. See code below

stage.addEventListener(Event.CLICK, handleClick, false, 0, true);

Nod to the wondeful gSkinner for this.

AS3 Email Validation Code Snippets - Regular Expression

Regular expressions are something that were introduced in AS3 with a sigh of relief from all flash developers. Yay

Below is a code snippet posted by senocular at kriupa

function isValidEmail(email:String):Boolean {    
var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
 
return emailExpression.test(email);
 
}
 
//...
 
trace(isValidEmail("senocular@example.com")); // true
 
trace(isValidEmail("@example.com")); // false
 
trace(isValidEmail("senocular@example")); // false
 
trace(isValidEmail("seno\\cular@example.com")); // false

Its a beautiful thing.

Flash Player Update Now Available (Flash Player 9,0,124,0)

Last week adobe released there latest flash player

Find it here.
http://www.adobe.com/go/getflashplayer

Simple Button Class - AS3

The SimpleButton class is a sweet way to put sprites together to make a button. The SimpleButton is a light weight alternative to the heavier MovieClip object.

var myButton:SimpleButton = new SimpleButton();
myButton.upState = mySprite1;
myButton.overState = mySprite2;
myButton.downState = mySprite3;
myButton.hitAreaState = mySprite4;

You can also draw your sprites on the fly.


var myButton:SimpleButton = new SimpleButton();

//create the look of the states
var down:Sprite = new Sprite();
down.graphics.lineStyle(1, 0x000000);
down.graphics.beginFill(0xFFCC00);
down.graphics.drawRect(10, 10, 100, 30);

var up:Sprite = new Sprite();
up.graphics.lineStyle(1, 0x000000);
up.graphics.beginFill(0x0099FF);
up.graphics.drawRect(10, 10, 100, 30);

var over:Sprite = new Sprite();
over.graphics.lineStyle(1, 0x000000);
over.graphics.beginFill(0x9966FF);
over.graphics.drawRect(10, 10, 100, 30);

// assign the sprites
myButton.upState = up;
myButton.overState = over;
myButton.downState = down;
myButton.hitTestState = up;

Detect when the mouse leaves the movie.

I previous of flash there was no way to detect when the users mouse had left the flash movie.

Actionscript 3 now allows you to detect when the users mouse has left the movie using the mouseLeave event.

Lets take a look:

package {
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class mouseLeaveTest extends Sprite {

        public function mouseLeaveTest() {
            stage.addEventListener(Event.MOUSE_LEAVE, mouseHasLeft);
        }

        public function mouseHasLeft)(e:Event):void {
            trace('Mouse have left the stage');
        }

    }
}
 Page 1 of 4  1  2  3  4 »
Close
E-mail It