Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Check connection with Zinc

function isConnected():Boolean {
var results = mdm.Network.checkConnection();
return results;
}
var hasConnection = isConnected();
mdm.Dialogs.prompt(hasConnection);

Internet Connection: Flash 8 Only.

var connected:Boolean = false;
function checkConnection():Void {
var myLoadVars:LoadVars = new LoadVars();
myLoadVars.onHTTPStatus = function(httpStatus:Number) {
if (httpStatus != 0) {
connected = true;
} else {
connected = false;
}
delete this;
};
myLoadVars.load("http://www.apple.com");
}
checkConnection();

Using FlashObject and the miniFLV player to play videos from an entry

Ideally, at some point, I'll modify the plug-in for EE that shows Flash objects to use flashobject.js.

This code assumes custom fields in the blog.

FlashObject: http://blog.deconcept.com/flashobject/
MiniFLV: http://www.richnetapps.com/miniflv.htm

Online Example.

{if project_video}
{if project_video_title}<h4>{project_video_title}: Video Clip</h4>{/if}

<div id="videoClip">
<p style="margin: 10px 0; padding: 10px; border: 3px solid red;"><a href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank" title="Get Flash Player"><img src="http://www.macromedia.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Flash Player" height="31" width="88" align="left" style="padding-right: 10px"></a>Flash 7 or above and JavaScript are required to view the project video clip. Please download the <a href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank" title="Get Flash Player">latest Flash plug-in</a>.</p>
{if project_video_alt}<p>{project_video_alt}</p>{/if}
</div>

<script type="text/javascript">
   // define the flash video movieclip that plays the videos
   var fo = new FlashObject("/images/videoplayer.swf", "video", "340", "230", "7", "#ffffff");
   fo.addVariable("file", "{project_video}"); // pass the clip name from the project_video field in entry
   fo.addVariable("aplay", "false");// autoplay
   fo.addVariable("size", "true"); //autosize
   fo.addVariable("autorew", "true"); //auto-rewind; doesn't work for some reason
  fo.write("videoClip"); // replace the targeted div with a Flash Object
</script>

{/if}

SetTimeout : Flash

function testMe() {
 trace("callback: "+getTimer()+" ms.");
}

var intervalID:Number = setTimeout(testMe, 1000);

// clearTimeout(intervalID) // for clear the timeout

Dynamically placed buttons

It's simple, yet I often forget this.

var myMC:MovieClip;
var i = 1;
var pad = 5;
while (i<6) {
	trace(" i : "+i);
	myMC.duplicateMovieClip("myMC"+i, i);
	myMC.removeMovieClip();
	this["myMC"+i]._x = this["myMC"+(i-1)]._x+(this["myMC"+(i-1)]._width)+pad;
	this["myMC"+i].onRollOver = function() {
		trace(this);
	};
	i++;
}

Retreiving a Flash movie's domain name

Use the LocalConnection object to get the domain name of the server where the Flash movie is located.

var localDomainLC:LocalConneciton = new LocalConnection();
myDomainName = localDomainLC.domain();
trace( "My domain is " + myDomainName );



This will print out something like this:

My domain is example.com


Use Flash's MovieClipLoader Class

I'm always forgetting the syntax for this...

var oImgListener = new Object();
oImgListener.onLoadInit = function(target_mc)
{
     trace(target_mc._name + "  load complete");
     ...
}

var mclImg = new MovieClipLoader();
mclImg.addListener(oImgListener);
mclImg.loadClip("http://myurl.com/path/to/swf/or/jpg", mcImgLoader);