var imgPath:String="http://93.97.40.201/snapshot/snaps/19cdeb13f7c46bfafa75beeca361c916.png";
var _loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress);
_loader.load(new URLRequest(imgPath));
function onProgress(e:ProgressEvent):void {
var _progress:String="Loading "+e.bytesLoaded+" of "+e.bytesTotal;
var _percent:Number=Math.round(100*e.bytesLoaded/e.bytesTotal);
trace(_percent + "%");
}
function onComplete(e : Event):void {
var loaderInfo:LoaderInfo=e.target as LoaderInfo;
var displayObject:DisplayObject=loaderInfo.content;
stage.addChild(displayObject);
trace("Loading Complete!");
}
Archive for the ‘Actionscript’ Category
AS3 Loading Images Externally
Tuesday, May 11th, 2010AS3 Video Code Snippets
Thursday, May 6th, 2010Few handy code Snippets for when using AS3 & Video.
This can be used with FLVPlayBack Component (just remove the vars/addChilds etc):
import fl.video.*;
var myVideo:FLVPlayback = new FLVPlayback();
myVideo.source = "video.flv";
myVideo.skin = "SkinOverPlayStopSeekFullVol.swf";
myVideo.addEventListener(VideoEvent.COMPLETE, completePlay);
function completePlay(e:VideoEvent):void {
myVideo.alpha=0.2;
}
addChild(myVideo);
Net Stream Version:
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream=new NetStream(nc);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
ns.play("video.flv");
function asyncErrorHandler(event:AsyncErrorEvent):void {
// ignore error
}
var vid:Video = new Video();
vid.attachNetStream(ns);
addChild(vid);
pauseBtn.addEventListener(MouseEvent.CLICK, pauseHandler);
playBtn.addEventListener(MouseEvent.CLICK, playHandler);
stopBtn.addEventListener(MouseEvent.CLICK, stopHandler);
togglePauseBtn.addEventListener(MouseEvent.CLICK, togglePauseHandler);
function pauseHandler(event:MouseEvent):void {
ns.pause();
}
function playHandler(event:MouseEvent):void {
ns.resume();
}
function stopHandler(event:MouseEvent):void {
// Pause the stream and move the playhead back to
// the beginning of the stream.
ns.pause();
ns.seek(0);
}
function togglePauseHandler(event:MouseEvent):void {
ns.togglePause();
}
ns.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
function statusHandler(event:NetStatusEvent):void {
trace(event.info.code);
/*
NetStream.Play.Start
NetStream.Buffer.Empty
NetStream.Buffer.Full
NetStream.Buffer.Empty
NetStream.Buffer.Full
NetStream.Buffer.Empty
NetStream.Buffer.Full
NetStream.Buffer.Flush
NetStream.Play.Stop
NetStream.Buffer.Empty
NetStream.Buffer.Flush
*/
switch (event.info.code) {
case "NetStream.Play.Start" :
trace("Start [" + ns.time.toFixed(3) + " seconds]");
break;
case "NetStream.Play.Stop" :
trace("Stop [" + ns.time.toFixed(3) + " seconds]");
break;
}
}
AS3/AS2 Dynamic Gradient Mask Effect
Sunday, April 11th, 2010maskMovieClip = Instance name of your mask movie clip this is where you add the gradient/radial colour/type.
movieClip = Instance name of your movie clip you want masking.
AS3
movieClip.mask = maskMovieClip; maskMovieClip.cacheAsBitmap = true; movieClip.cacheAsBitmap = true;
AS2
movieClip.cacheAsBitmap = true;
maskMovieClip.cacheAsBitmap = true;
mask.cacheAsBitmap = true;
movieClip.setMask("maskMovieClip");
AS3 Stage Preloader / Loader
Monday, January 18th, 2010Happy new year ![]()
Here’s a AS3 preloader.
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS , onLoadProgress);
this.loaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
function onLoadProgress(event:ProgressEvent):void {
var bl:uint = event.bytesLoaded;
var bt:uint = event.bytesTotal;
var percentLoaded:int = Math.floor((bl/bt) * 100);
trace( String(percentLoaded) ); //trace percent loaded
}
function onLoadComplete(event:Event):void {
trace("loading complete!"); //trace load completed
}
AS3 detect page title and URL ExternalInterface.call
Friday, August 14th, 2009This is very handy script if you are trying to see where exactly the SWF has been loaded from you can read the Title of the page and the URL by using “ExternalInterface.call” method.
var title:String = ExternalInterface.call('window.document.title.toString');
var <a href="url:String">url:String</a> = ExternalInterface.call('window.location.href.toString');
res.appendText( "url = "+url+" \ntitle = "+title ); //add a text field to the stage called "res"
Example (note that this is sitting in a iframe @ http://sputn1k.co.uk/labs/url/)
AS3 Making thing’s Move the OOP way :)
Friday, July 3rd, 2009**Updated! – added more parameters/features.
Just wrote this small snippet of code right now shows how simple it is to get this moving with AS3 and and a OOP methodology. that’s it enjoy
/*///////////////////////////////////////////////////
Animate Script | by Kurt Grung - 3L3373.com
Usage:
---
"mc" movieClip = obj:Object
"type" x,y,alpha,rotate = prop:String
"style" Strong.easeOut = func:Function
"str" = begin:Number
"fin" = finish:Number
"len" = duration:Number [,useSeconds:Boolean=false]
See below for examples of use;
///////////////////////////////////////////////////*/
//imports
import fl.transitions.*
import fl.transitions.easing.*
//funtion
function animate(mc:MovieClip, type:String, style:Function, str:Number, fin:Number, len:Number){
//
var tween:Tween;
tween = new Tween(mc, type, style, str, fin, len, true);
}
//animations
animate(mc, "x", Strong.easeOut, -20, 300, .90 );
animate(mc, "y", Elastic.easeOut, -20, 200, .90 );
animate(mc, "alpha", Strong.easeOut, 0, 1, 3.5 );
AS3 Stage.width Stage.height Example
Monday, June 22nd, 2009Adobe has changed the syntax in AS3 for AS2 Stage.width/Stage.height equivalence (see below).
Code examples:
stage.stageWidth; stage.stageHeight;
Getting the middle of the stage.
stage.stageWidth/2 stage.stageHeight/2
Aligning your “MovieClip” into the middle of the stage.
MovieClip.x=stage.stageWidth/2-MovieClip.width/2; MovieClip.y=stage.stageHeight/2-MovieClip.height/2;
You don’t need to add the brackets – Replace “MovieClip” above with your MC instance name – That’s it you ready to roll.
Differences between ActionScript 1/2/3 :)
Friday, June 5th, 2009as3.0 is like a strict german mistress. Very harsh but gets good results.
as2.0 is your stoner friend from college.as1.0 is for script-kiddies, designers and other non-technical people
as2.0 is for girls
as3.0 is for real menas3.0 is carefully crafted formulaic pop – predictable, slick, reliable, dull
as2.0 is glitchy electronica – some semblance of form, but playful with it
as1.0 is a child bashing saucepans – imprecise, messy, but lots of funas3.0 is a Japanese Chef’s knife. Finely crafted but requires care and technique in its use.
as2.0 is a Machete. Great for hacking things, but useless for anything requiring fine detail or control.
as1.0 is a plastic spoon.
Haha!! amazing.
Found @ http://actionscripter.co.uk/blog/?p=237














