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
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"; }
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.
Last week adobe released there latest flash player
Find it here.
http://www.adobe.com/go/getflashplayer
Returns the number of words in a string.
function wordcount(string:String):Number {
var wrdArray:Array = string.split(" ");
for (var i = wrdArray.length; i>0; i--) {
if (wrdArray[i] == "") {
wrdArray.splice(i,1);
}
}
return wrdArray.length;
}
trace(wordcount("This will count the number of words"));Here is how you find all the movieclips inside an object in as3
var desc:XML = describeType(my_mc);
for each (var node:XML in desc.variable) {
if (node.@type == "flash.display::MovieClip") {
if (my_mc.getChildByName(node.@name.toString())) {
trace("child mc found");
}
}
}This example shows you how to load and external asset (file) in AS3. The files can be a swf, jpg, gif or png.
This particular example loads a jpg called loademe.jpg and attaches to the stage
Load Asset / external files example
// loadAsset.as
package {
import flash.display.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
public class loadAsset extends Sprite{
private var _loadPath:String
private var _loader:Loader;
// Constructor
public function loadAsset(){
// Create the loader
_loader = new Loader();
// Add event listener that tells us when the
// asset can be safely accessed
_loader.contentLoaderInfo.addEventListener(Event.INIT, displayAsset);
// Create new URLRequest
var urlRequest = new URLRequest("loadme.jpg")
// Start the asset load
_loader.load(urlRequest);
}
// Display the asset once the load is complete
private function displayAsset(ev:Event){
// it to the DisplayObjectContainer
addChild(_loader.content);
}
}
}
To load the asset/file you need to open the flash file and place this AS in the timeline
import loadAsset; addChild(new loadAsset());
In AS3 mouse event a handled differently than in AS2. Here is the general procedure for adding a click event to a object.
Full code after the jump.
Mouse Event - click
// you will need a movieclip on the stage with an instance name of cir_mc
// or just download the file above (www.flashcs.org)
cir_mc.addEventListener(MouseEvent.CLICK, clickListner);
function clickListner(ev:MouseEvent):void{
trace("Circle Clicked");
}In AS3 mouse event a handled differently than in AS2. Here is the general procedure for adding a mouse up event to a object.
Mouse Event - up
// you will need a movieclip on the stage with an instance name of cir_mc
// or just download the file above (www.flashcs.org)
cir_mc.addEventListener(MouseEvent.MOUSE_UP, clickListner);
function clickListner(ev:MouseEvent):void{
trace(”Mouse Up”);
}
In AS3 mouse event a handled differently than in AS2. Here is the general procedure for adding a mouse over event to a object.
Mouse Event - over
// you will need a movieclip on the stage with an instance name of cir_mc
// or just download the file above (www.flashcs.org)
cir_mc.addEventListener(MouseEvent.MOUSE_OVER, clickListner);
function clickListner(ev:MouseEvent):void{
trace("Mouse Over Circle");
}