Wednesday 20 February 2008

AS3 cheat sheet

Found a nice cheat sheet for migration from AS2 to AS3:

http://www.actionscriptcheatsheet.com/downloads/as3cs_migration.pdf

Tuesday 19 February 2008

AS3 -AttachMovieClip is no more!!

yea, it always sounded old, AS3 works without it. A common way of including an graphical object to the stage follows. I include a way of embedding an image straight away:

package {
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
public class Test extends MovieClip {
// be sure this is pointing to an image in your hardrive
[Embed(source='\images\whatsup.jpg')] public var MyImage:Class;
public function Test() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var img:MyImage = new MyImage();
addChild(img);
}
}
}

Just attaching a symbol from the Library to the stage here:

package {
import flash.display.MovieClip;
public class Test extends MovieClip {
public var MyLibrarySymbol:MovieClip;
public function Test() {
var mc:MyLibrarySymbol= new MyLibrarySymbol();
addChild(mc);
}
}
}

Sunday 17 February 2008

The Stage Object in a Flash CS3 Movie

the stage is treated as an Object in AS3. Here a small collection of articles on the oddities and possibilities of working with the stage object in AS3.
The first article shows the different ways of referencing the stage and it's children.

Basically here the short list of queries to have some information of the stage and it's children:

trace("Number of children of the Stage: ");
trace(stage.numChildren);

trace("What are children of Stage: ");
trace(stage.getChildAt(0));

trace("What does the keyword this refer to? ");
trace(this);

trace("Number of children of MainTimeline: ");
trace(this.numChildren);

trace("Are this.stage and stage the same? ");
trace(this.stage == stage);

trace("How many children does this.stage have? ");
trace(this.stage.numChildren);

trace("What are the children of this.stage? ");
trace(this.stage.getChild(0));


http://www.flashandmath.com/intermediate/children/stage.html

the good collection of senocular classes includes a custom stageDetection class:

http://www.senocular.com/flash/actionscript.php?file=ActionScript_3.0/com/senocular/events/StageDetection.as

Wednesday 6 February 2008

A Lightweight (2K) and FAST Tweening Engine in AS3: TweenLite

While we a re still waiting for Zigo/Fuse to update their engine, I started using TweenLite, and really start liking it.
http://blog.greensock.com/tweenliteas3/
It is light (2kB), and fast, does rely on flashes built in easing classes though. It is rather basic, but useful for almost all purposes.
here a simple example, of a sequenced animation with :

import gs.TweenLite;
import fl.motion.easing.Elastic;
TweenLite.to(mc_my, 0.8, {x:120, y:143,ease:Elastic.easeOut,delay:2,onComplete:onFinishTween, onCompleteParams:[5, mc_my],overwrite:false});
private function onFinishTween(Num,target_mc){
trace("tween finished "+target_mc
}

onEnterFrame in AS3

the old 'onEnterFrame' syntax has been removed in AS3 It seems everything has to be handled by the eventListener. Here's a simple


import flash.events.Event;
addEventListener(Event.ENTER_FRAME, dosmthng);
//
private function dosmthng(Event){
trace("smthng"+Event)//output:smthng[Event type="enterFrame" bubbles=false ...
}

and to remove it? Well, it’s a listener so you have to remove the Event Listener with :

removeEventListener(Event.ENTER_FRAME,funcToCall)

Besides ENTER_FRAME we have other Public Constants to use:

  • ACTIVATE
  • ADDED
  • ADDED_TO_STAGE
  • CANCEL
  • CHANGE
  • CLOSE
  • COMPLETE
  • CONNECT
  • DEACTIVATE
  • ENTER_FRAME
  • FULLSCREEN
  • ID3
  • INIT
  • MOUSE_LEAVE
  • OPEN
  • REMOVED
  • REMOVED_FROM_STAGE
  • RENDER
  • RESIZE
  • SCROLL
  • SELECT
  • SOUND_COMPLETE
  • TAB_CHILDREN_CHANGE
  • TAB_ENABLED_CHANGE
  • TAB_INDEX_CHANGE
  • UNLOAD

Flash ReferenceError: Error #1065: Variable Application is not defined.

If you are receiving this error when publishing your flash as3 swf it is because you need to declare your class as public. Private classes can not be used as document classes because they are out of the class package and therefore are not a part of the private scope.

I’ve seen a bunch of people with this problem so I hope this helps. (courtesy of http://optimastudios.com)

AS3 stage properties

getting the Stage Properties in AS3 has changed.
Just use stage.stageWidth and stage.stageHeight ..NOT Stage.width and Stage.height !