Simple Actionscript

Wednesday, June 17, 2009

wmode broken in Flash player 10

After testing our content in Flash player 10 we noted strange display issues. For example elements will appear out of place or repeated or just missing. We tracked this to the "transparent" property of "wmode" in the html embed code.

So if you are having strange display issues using the plugin version 10 try disabling the wmode.

Thursday, June 11, 2009

Detecting if flash is running on a browser or standalone

If for some reason we need to know if flash is running a browser, projector or the flash ide we can use this code:


import flash.system.Capabilities;

var type:String = Capabilities.playerType;

switch(type){
case "External":
//Flash IDE
break;
case "StandAlone":
//Projector
break;
case "PlugIn":
//Firefor or Safari
break;
case "ActiveX":
//IE
break;
}

FLV paths

Normally all paths in Flash are relative to the html page containing the movie. Note however that paths to flv are relative to the swf files, not the html. This is a problem when the html and the swf file are not in the same folder.

Tuesday, June 9, 2009

How to load a swf in AS3

Here is how to load an external SWF or JPG file



import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.errors.IOError;


var url = "...";

var loader:Loader = new Loader();
var urlreq:URLRequest = new URLRequest(url);

//add listeners:

loader.contentLoaderInfo.addEventListener(Event.INI, handleLoadIni);//This is called in the first frame of the movie not when the whole movie is loaded

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoadComplete);//Called when the whole movie is done loaded

loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);//Called if the movie fails to load

loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, handleProgress); //Used for preloader

//load
loader.load(urlreq);

private function handleLoadComplete(event:Event):void {
var loader = event.target.loader; //reference to the loader object
var content = event.target.content; //reference to the swf

this.addChild(content); //adds the movie to the stage
}

Followers