Posts Tagged ‘AS3’

AS3 Escape / Unescape Method

Friday, August 13th, 2010
var data:String = "< \"Hello World!\" />";
trace("data= "+data);

var escaped:String = escape(data);
trace("escaped= "+escaped);

var pattern:RegExp = /\+/g;
var unescaped:String = unescape(data).replace(pattern, " ");
trace("unescaped= "+unescaped);

/*
	Output ++
	data= < "Hello World!" />
	escaped= %3C%20%22Hello%20World%21%22%20/%3E
	unescaped= < "Hello World!" />
*/
Vote in HexoSearch

AS3 Loading Images Externally

Tuesday, May 11th, 2010
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!");
}
Vote in HexoSearch

AS3 Video Code Snippets

Thursday, May 6th, 2010

Few 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;
	}
}
Vote in HexoSearch

AS3/AS2 Dynamic Gradient Mask Effect

Sunday, April 11th, 2010

maskMovieClip = 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");
Vote in HexoSearch

iPhone SDK 3.3 on OSX 10.5.5

Friday, March 5th, 2010

Can’t get? iPhone SDK 3.3 with xCode 2.1.4 running inside Mac OSX 10.5.5, I have it running on VMware with Mac OSX 10.5.5 here’s how:

Download iPhone SDK 3.3 with xCode 2.1.4 from Apple here.

Then do the following:

Edit the version number from 10.5.5 to 10.5.7 inside the “SystemInfo.plist” file which is located here:

/System/Library/Core Services/SystemInfo.plist

Now you can install the latest iPhone SDK without any crappy messages coming up :)

Vote in HexoSearch

AS3 Stage Preloader / Loader

Monday, January 18th, 2010

Happy 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
}
Vote in HexoSearch

Flash AS3 clickTag & clickTAG-substr Snippets

Friday, October 23rd, 2009

This have changed since AS2 clickTags ;0 I have two examples below, clickTag normal way and clickTAG with substr as some adservers use that convention, you should checkout Banner Flow easy tool to test if clickTags are working correctly.

AS3 clickTag Code:

import flash.display.LoaderInfo;
var clickTag = root.loaderInfo.parameters.clickTag;
var url:String = "http://domainName.com"; //I use this as its better when sending to clients when the click down on the banners they don't see a 'Undefined' blank page.
clickTagBtn.addEventListener(MouseEvent.MOUSE_DOWN, clickTagPress);

function clickTagPress(event:MouseEvent):void {
	if( clickTag == undefined ){
		//
		var request:URLRequest = new URLRequest(url);
		flash.net.navigateToURL(request, "_blank");
	}else{
		//
		var requestCT:URLRequest = new URLRequest(clickTag);
		flash.net.navigateToURL(requestCT, "_blank");
	}
}

AS3 clickTAG-substr code:

var url:String = "http://domainName.com"; //Again - I use this as its better when sending to clients when the click down on the banners they don't see a 'Undefined' blank page.
var ct:String = LoaderInfo(root.loaderInfo).parameters.clickTAG;
if (LoaderInfo(root.loaderInfo).parameters.clickTAG){
    clickTagBtn.addEventListener(MouseEvent.MOUSE_UP, ctPress);
}else{
    clickTagBtn.addEventListener(MouseEvent.MOUSE_UP, urlPress);
}
function ctPress(event:MouseEvent):void{
	if (ct.substr(0,4) == "http") {
		navigateToURL(new URLRequest(ct), "_blank");
	}
}
function urlPress(event:MouseEvent):void{
	navigateToURL(new URLRequest(url), "_blank");
}
Vote in HexoSearch

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 );
Vote in HexoSearch

AS3 Stage.width Stage.height Example

Monday, June 22nd, 2009

Adobe 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.

Vote in HexoSearch

AS3 loading variables from external flash SWF files through contrainer levels

Wednesday, April 22nd, 2009

This is an example for anyone coming from AS2 and wants to access variables from another SWF through movie clip container levels.

Previously you would just do this allot has changed since then in AS3 :)


container.loadMovie("fileName.swf"); //load the external SWF file.
trace( container.vars ); //access variables directly from the loaded external SWF by tracing etc.
container.functionX(); //directly call a function from another SWF file from a container level. 

This got me puzzled at first couldn’t find much information about it on Adobe labs. I was building a remote Shared Objects loader/writer which needed to work crossdomain as it was been built into an advert and needed to write the flash cookies to one domain (as you know Shared Objects data write by default to the current domain it’s been severed from) and then there was an additional SWF file sitting on another remote server that also needed to have access (reading & writing) to those Shared Objects data.

Unit A – loads in the SWF file remotely if needed (you will need crossdomain policy file or allow domain XXX to allow remote accessing of variables).
Unit B – contains “init” function that can pass strings directly through to be traced. the “helloWorld” variable can be accessed from Unit A.

Unit A


//crossdomain
Security.allowDomain("*");

//imports
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest;

//loader
var domain = ""; //www.domain.com/path/etc/
var url = domain + "unitB.swf";
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.INIT, onLoaderInit );
loader.load( new URLRequest( url ));

//onload function
function onLoaderInit( e:Event ):void {
 Object( loader.content ).init( "Hello World!" ); //Passing the var to unitB
 trace( Object(loader.content).helloWord ); //calling a remote variable "helloWord" from unitB by first loading the SWF
}

Unit B


//crossdomain
Security.allowDomain("*");

//variable
var helloWord = "Hello World!";

//function to pass paramaters with a trace
function init( param:String ):void{
 trace( param ); //Hello World!
}

Here ‘s another example how to gain access to levels or vars from within an external SWF (obviously you will need to use a loader class first to load in the external SWF then set the object/loader.content).

//Main SWF
var externalSWF = Object( loader.content ); //
vars = externalSWF.vars;
trace(vars);

function helloWorld(){
 trace("Hello World! (via MainSWF - Root Level)")
}

//External SWF
var vars:String = "Hello World! (via ExternalSWF)";

if(this.parent.parent != null){
 var parentLvl:Object = this.parent.parent as Object;
 parentLvl.hello(); //call a function on root level.
}
Vote in HexoSearch
  • Categories

  • Recent Comments

  • Recent Posts

  • Tumblr

  • Flickr Recent Photos

    cherry tree woodstonja_gravestonesPockey Chimp FlavourAUTO FTW! :)darkdaystayouttiger kittenbirdofpreyfirst photo i took with my 1000dself_portrait_02
  • XFIRE (wkly hrs pld)

  • Last.FM

  • Tags

    .MP4 Actionscript Action Script Advertising AS2 AS3 backtrack BT4 bug Call of Duty capcom centOS COD count down countdown crossdomain Eyeblaster eyeblaster HD f4v Flash h264 HD high definition Install internet explorer Linux loadMovie MIME MIME Types MW2 Nazi Zombies pc PHP ports preloader release date rich media shared objects SWF SWFOBJECT timer torrents Video video/mp4 win7