Tag Archives: Flash

Valid XHTML flash embed code

You’ll be disheartened for the first time when you attempt to validate your flash embedded html page on W3C. Here is the basic structure for valid swf embed code:

<object type="application/x-shockwave-flash" data="movie.swf" width="250" height="25">
	<param name="movie" value="movie.swf" />
</object>

It’s often a big pain after embedding YouTube (or any other) videos, cos your page will no longer be W3 valid! There are many free online tools to convert youtube embed code to valid xhtml format. You may try this one from tools4noobs. It works great.

Calling a function randomly / arbitrarily

Say you have 2 or more functions in your actionscript, for some reason you have to call one of them arbitrary and dynamically. You don’t know which function will call at run time. You can do it by this way….

var myfunctions:Array = new Array();
myfunctions[0] = "myfunc1";
myfunctions[1] = "myfunc2";
myfunctions[2] = "myfunc3";

function  myfunc1 (){
   trace("This is my function number 1");
}
function  myfunc2 (){
   trace("This is my function number 2");
}
function  myfunc3 (){
   trace("This is my function number 3");
}

function randRange(min:Number, max:Number):Number {
   var randNum:Number = Math.round(Math.random()*(max-min))+min;
   return randNum;
}
btn.onPress = function(){
   var randomNumber = randRange(0,myfunctions.length-1);
   _root[myfunctions[randomNumber]]();
}