Archive for the ‘Actionscript’ Category

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

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 detect page title and URL ExternalInterface.call

Friday, August 14th, 2009

This 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/)

Adobe Labs
AS2
AS3

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

Posting Content to Myspace via Flash or HTML

Thursday, June 25th, 2009

For example:

http://www.myspace.com/Modules/PostTo/Pages/?t=TITLE&c=CONTENT&u=URL&l=1

Replace the query strings with your content. Here is the dissection of the Myspace query strings.  All data needs to be passed “escaped”.  From what I have seen is Myspace disables to click-throughs from SWF embedded content.

Actionscript “escape” example:

var escapeDATA:String = "< OMFGBBQ_ THIS PWNZ - w00t!! >";
escapeDATA = escape(escapeDATA);
trace("escapeDATA= "+escapeDATA);
?t=

TITLE

?c=

CONTENT – this where you would add your embed tags.

i.e. this is encoded/escaped string.

<embed width%3D'555' height%3D'360' allowFullScreen%3D'true' allowNetworking%3D'all' allowScriptAccess%3D'always' src%3D'http%3A%2F%2Fdomainname.com%2Fdir%2Fname.swf' type%3D'application%2Fx-shockwave-flash' >
?u=

URL

l=

1 = blog
2 = bulletin
3 = profile, about me

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

Differences between ActionScript 1/2/3 :)

Friday, June 5th, 2009

as3.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 men

as3.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 fun

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

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 cpanel crossdomain Eyeblaster eyeblaster HD f4v Flash h264 HD high definition Install internet explorer Linux load loadMovie MIME MIME Types MW2 Nazi Zombies pc PHP ports preloader release date rich media shared objects Stage SWF SWFOBJECT torrents Video video/mp4 VMware win7