Content

Visual communicator / logbook & brain bin

Navigating the timeline ++

Tuesday 29 September 2009 - Filed under Actionscript/Flash + Animation + General

This project demonstrates timeline navigation, key stroke detection, a basic URLRequest, context menu modification, and how to make an object annoyingly trail the mouse cursor. The code follows after the jump.

timeline

Setting up the navigation

stop();
btn_start.addEventListener(MouseEvent.CLICK, gotostart);
btn_one.addEventListener(MouseEvent.CLICK, gotoone);
btn_two.addEventListener(MouseEvent.CLICK, gototwo);
btn_three.addEventListener(MouseEvent.CLICK, gotothree);


function gotostart(e:MouseEvent):void {
gotoAndPlay("frame_start"); // frame labels, defined in the properties panel
}
function gotoone(e:MouseEvent):void {
gotoAndPlay("frame_one");
}
function gototwo(e:MouseEvent):void {
gotoAndPlay("frame_two");
}
function gotothree(e:MouseEvent):void {
gotoAndPlay("frame_three");
}

START: Detecting key strokes

stop();
stage.addEventListener(KeyboardEvent.KEY_DOWN, nudge);

function nudge(e:KeyboardEvent):void {
if (e.keyCode==Keyboard.RIGHT){
purpleball.x += 10;
}
if (e.keyCode==Keyboard.LEFT){
purpleball.x -= 10;
}
if (e.keyCode==Keyboard.UP){
purpleball.y -= 10;
}
if (e.keyCode==Keyboard.DOWN){
purpleball.y += 10;
}
}

ONE: Go to external URL


stop();
var portfoliourl:URLRequest = new URLRequest();
portfoliourl.url="http://www.asgeirhoem.no/portfolio";
btn_external.addEventListener(MouseEvent.CLICK, gotoexternalsite);


function gotoexternalsite(e:MouseEvent):void{
navigateToURL(portfoliourl);
}

TWO: Editing the context menu


stop();
var myMenu:ContextMenu = new ContextMenu();
myMenu.hideBuiltInItems();
myObject.contextMenu = myMenu;

THREE: Mouse cursor


stop();
trail.addEventListener(Event.ENTER_FRAME, followcursor);
function followcursor(e:Event):void {
trail.x = mouseX;
trail.y = mouseY;
}

Tagged: » »

2009-09-29  »  Asgeir

Share your thoughts

Re: Navigating the timeline ++







Tags you can use (optional):
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>