Navbar/gallery project
Posted: February 26th, 2009 | Author: Janice | Filed under: Uncategorized | No Comments »
some navbar/gallery i’ve been working on: XMLLoader (class), Navigation (class), document class (constructor).
( +flash )

some navbar/gallery i’ve been working on: XMLLoader (class), Navigation (class), document class (constructor).
( +flash )
1 2 3 | private var container:MovieClip = new Container(); private var content:MovieCLip = new Content(); // where container is your stage, and content is the material you want to center |
Initialize your stage listeners/event listeners.
1 2 3 4 5 6 7 8 9 10 11 12 | function init() { stage.align=StageAlign.TOP_LEFT; stage.scaleMode=StageScaleMode.NO_SCALE; stage.addEventListener(Event.RESIZE, updateSize); stage.dispatchEvent(new Event(Event.RESIZE)); container.x = 0; container.y = 0; } |
updateSize gets called every time the stage gets resized.
1 2 3 4 5 6 7 8 9 10 11 | function updateSize(e:Event) { // make container width/height equal to stage.width/height container.width = stage.stageWidth; container.height = stage.stageHeight; //center content content.x = stage.stageWidth/2 - content.width/2; content.y = stage.stageHeight/2 - content.height/2; } |
You can choose to overwrite tweens:
1 2 | TweenLite.to(mc, 1, {x:100, y:200}); TweenLite.to(mc, 1, {x:300, overwrite:2}); //only overwrites the "x" property in the previous tween |
you can pass 0, 1, 2, or 3 to overwrite.
According to GreenSock’s site:
0 (NONE): No tweens are overwritten. This is the fastest mode, but you need to be careful not to create any tweens with overlapping properties, otherwise they’ll conflict with each other.
1 (ALL): (this is the default unless OverwriteManager.init() has been called) All tweens of the same object are completely overwritten immediately when the tween is created.
2 (AUTO): (used by default if OverwriteManager.init() has been called) Searches for and overwrites only individual overlapping properties in tweens that are active when the tween begins.
3 (CONCURRENT): Overwrites all tweens of the same object that are active when the tween begins.
Basic line drawer: (preview link)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | // add stage listeners stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown); stage.addEventListener(MouseEvent.MOUSE_UP, onUp); function onDown(e:Event):void { graphics.moveTo(mouseX, mouseY); addEventListener(Event.ENTER_FRAME, onLoop); } function onUp(e:Event):void { removeEventListener(Event.ENTER_FRAME, onLoop); } // bit shifting colours function onLoop(e:Event):void { graphics.lineStyle((Math.random()*45), Math.random()*0xFFFFFF >> 23, Math.random(), true, "normal"); // blue=black graphics.lineTo(mouseX, mouseY); } |
A button component in MXML:
1 | <mx:Button x="10" y="10" label="myButton" id="newButton" click="checkForm()"> |
MXML is converted to AS3 when you compile it. MXML is used to define the structure of your Flex application, and Actionscript is used to define behavior.
TweenLite is a small and fast tweening engine for Flash Player 9 (AS3). TweenLite only adds about 3KB to published .swfs.
Somewhere above your constructor:
1 2 | import gs.TweenLite; import gs.easing.*; |
Basic TweenLite function:
TweenLite.to tweens from an initial point to that point that you define. Position the clip on the stage where/how you want the tween to start.
1 2 | TweenLite.to(circle, 1, {x:300, ease:Sine.easeIn}); // TweenLite.to(moviecliptotween, timeinsec, { .. properties... }); |
TweenLite.from does the opposite. Position the clip on the stage where you want the tween to end, and define where/how you want the tween to begin:
1 | TweenLite.from(circle, 1, {y:300, ease:Sine.easeIn}); |
Useful notes:
TweenLite has an onComplete function that you can map behaviour to upon finishing a tween.
1 2 3 4 5 | TweenLite.to(circle, 1, {onComplete:doneTween}; ... function doneTween():void { // finished tween, now do this } |
Somewhere above your constructor:
1 2 3 4 | import flash.ui.Mouse; import flash.events.*; ... var myButton:MovieClip; |
Create an instance of your button:
1 2 3 | myButton = new ButtonClass(); myButton.x = 10; // apply properties here |
Add event listeners and click handling function:
1 2 3 4 5 6 7 8 | myButton.addEventListener(MouseEvent.CLICK, clickHandler); // event listener private function clickHandler(e:MouseEvent) { buttonText.text = "button clicked"; var myTimer:Timer = new Timer(2000, 1); myTimer.addEventListener(TimerEvent.TIMER, timerListener); myTimer.start(); } |
Here is how to have a custom mouse cursor in AS3.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | package { import flash.display.Sprite; import flash.text.TextField; import flash.ui.Mouse; import flash.events.*; import flash.utils.Timer; public class CustomCursor extends Sprite { private var myCursor:cursor = new cursor(); public function CustomCursor():void { Mouse.hide(); addChild(cursorText); addChild(myCursor); myCursor.addEventListener(Event.ENTER_FRAME, init); } private function init(e:Event):void { myCursor.mouseEnabled = false; myCursor.x = mouseX; myCursor.y = mouseY; } } // end class } // end package |
( CustomCursor.fla, CustomCursor.as )