Convert number to hex code AS3

If you trace a colour you've input as 0xFFFFFF, it'll trace back as some big number (no time to do exmaple properly). If you need to say, then reuse this color number and put it back in to htmltext formatting for colour (which deals in hex) - you can use toString(16) to convert it back... Continue Reading →

Sending variables with an event – AS3

See this thread: http://stackoverflow.com/questions/792451/want-to-send-parameters-with-custom-dispatch-event Incase they remove it, public class YourEvent extends Event { public static const SOMETHING_HAPPENED: String = "somethingHappend"; public var data: Object; public function YourEvent(type:String, date: Object, bubbles:Boolean=false, cancelable:Boolean=false) { data = this.data; super(type, bubbles, cancelable); } override public function clone():Event { return new YourEvent (type, data, bubbles, cancelable); } }

Basic Image Loader in AS3

Basic wee loader which loads an image, then is put inside a container movieclip. // image loader var imageLoader:Loader = new Loader(); imageLoader.load(new URLRequest("thumbnails/example_thumb.jpg")); var myImage:MovieClip = new MovieClip(); myImage.addChild(imageLoader); addChild(myImage); If you want something to happen when it's loaded (like load the next one etc, slap a listener on the contentLoaderInfo beneath the loader.... Continue Reading →

Adding basic sounds in AS3

Where 'targetSound' is the class name you've exported your sound as in the FLA: var sound:Sound = new targetSound(); var soundChannel:SoundChannel = new SoundChannel(); soundChannel = sound.play();

Embedding fonts in textfields dynamically AS3

Embedding fonts dynamically into generated text fields might look complicated but it's not too bad once you get the hang of it. The below code creates a 'defaultFormat' which will be applied to all generated textFields - (setTextFormat(format) can be called to change it if required). // default textformat var textFormat:TextFormat = new TextFormat(); var... Continue Reading →

Keyboard events in AS3

To get the character code of something in AS3, add a keyboard event to the stage. // keyboard event stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler); function keyDownHandler(event:KeyboardEvent):void { if (event.keyCode == Keyboard.LEFT) { trace("LEFT!"); }

getURL / go to URL with AS3

A bit more to it than the old getURL in AS2: var url:String = "http://site"; var request:URLRequest = new URLRequest(url); try { navigateToURL(request, '_blank'); // second argument is target } catch (e:Error) { trace("Error occurred!"); } Source: http://scriptplayground.com/tutorials/as/getURL-in-Actionscript-3/

Moving vanishing point in AS3

// this can reset the location of the vanishing point var pp:PerspectiveProjection=new PerspectiveProjection(); pp.projectionCenter = new Point(mouseX,mouseY); this.transform.perspectiveProjection = pp;

Gradient Masks in AS3

You can do gradient alpha masks in Flash CS3/4, but not without doing a bit of actionscript. I beleive this works in both AS2 and 3, this works in AS3 - not bothering to test AS2. // set both the mask clip and the target to be masked to true maskMC.cacheAsBitmap = true; targetMC.cacheAsBitmap =... Continue Reading →

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑