AS3 Simple Menu

Flash Add comments

You will need tweenlite for this to work.

You can set the menu items via an array and disable the current button that is pressed.
if you want you can set the URLS in an array and have the selected button pull the URL from your array, right now it’s not being set to do that.

but it would go something like this.

var links:Array = new Array(“link1″,”link2″,”link3″);
then in setNav Function change the URLRequest to
navigateToURL (new URLRequest(links[thisOne]),”_blank”);

import flash.events.MouseEvent;
import com.greensock.*;
import com.greensock.plugins.*;
import com.greensock.easing.*;
import com.greensock.OverwriteManager;
import flash.display.MovieClip;

OverwriteManager.init();
TweenPlugin.activate([TintPlugin]);

var btns:Array = new Array(“home”,”away”,”long”,”about”,”links”,”bio”);
//var links:Array = new Array(“link1″,”link2″,”link3″);
var xPos:Number = 1;
var yPos:Number = 40;
var distance:Number = 1;
var delayBtn:Number = .1

var mHolder:MovieClip = new MovieClip();
mHolder.x = 1;
mHolder.y = stage.stageHeight – 54;
mHolder.name = “mHolder”;
addChild(mHolder);

for (var i:Number = 0; i<btns.length; i++) {
var btn:MovieClip = new MovieClip();
btn.graphics.beginFill (0x333333);
btn.graphics.drawRoundRect (0, 0, 100, 50, 10, 10);
btn.graphics.endFill ();
btn.x = xPos;
btn.y = yPos;
btn.id = i;
btn.name = “btn” + i;
btn.alpha = 1;
btn.addEventListener (MouseEvent.MOUSE_DOWN, btnDown);
btn.addEventListener (MouseEvent.MOUSE_OVER, btnOver);
btn.addEventListener (MouseEvent.MOUSE_OUT, btnOut);
btn.mouseChildren = false;
btn.buttonMode = true;
mHolder.addChild (btn);

var btnBkg:MovieClip = new MovieClip();
btnBkg.graphics.beginFill (0x555555);
btnBkg.graphics.drawRoundRect (-50, -25, 100, 50, 10, 10);
btnBkg.graphics.endFill ();
btnBkg.x = 50;
btnBkg.y = 25;
btnBkg.name = “bkg”;
btn.addChild (btnBkg);

var myFormat:TextFormat = new TextFormat();
myFormat.color = 0xffffff;
myFormat.size = 14;
myFormat.italic = false;
myFormat.font = “Univers 57 Condensed”;

var txtField:TextField = new TextField();
txtField.text = btns[i].toUpperCase();
txtField.width = 150;
txtField.x= (mHolder.getChildByName(“btn”+i).height – 105) / 2;
txtField.y= (mHolder.getChildByName(“btn”+i).height) / 3;
txtField.selectable = false;
txtField.border = false;
txtField.autoSize = TextFieldAutoSize.CENTER;
txtField.setTextFormat (myFormat);
btn.addChild (txtField);

TweenLite.to(btn, .25, {alpha:1,y:1, delay:delayBtn});

if (i < btns.length) {
xPos +=  100 + distance;
delayBtn += .1;
}
}

function btnDown (evt:MouseEvent):void {
trace (“you clicked ” + evt.target.name);
setNav (evt.target.id);
}
function btnOver (evt:MouseEvent):void {
TweenLite.to(evt.target, .5, {y:evt.target.y+5});
TweenLite.to(evt.target.getChildByName(“bkg”), 1, {x:(evt.target.width)/2, y:(evt.target.height)/2,scaleX:.05, scaleY:.05, alpha:0, ease:Back.easeInOut, tint:0xFFFFFF});
}
function btnOut (evt:MouseEvent):void {
if(evt.target.mouseEnabled == false){

}else{
TweenLite.to(evt.target, .5, {y:1});
TweenLite.to(evt.target.getChildByName(“bkg”), 1, {x:(evt.target.width)/2, y:(evt.target.height)/2 ,scaleX:.7, scaleY:.7, alpha:1, ease:Back.easeInOut, tint:0x555555});
}
}

function setNav (thisOne):void {
for (var n:Number = 0; n<btns.length; n++) {
var thisBtn1 = mHolder.getChildByName(“btn” + n);
thisBtn1.mouseEnabled = true;
TweenLite.to(thisBtn1, .5, {y:1});
TweenLite.to(thisBtn1.getChildByName(“bkg”), 1, {y:25,scaleY:.7, alpha:1, ease:Back.easeInOut, tint:0x555555});
}
var thisBtn2 = mHolder.getChildByName(“btn” + thisOne);
thisBtn2.mouseEnabled = false;
TweenLite.to(thisBtn2, .5, {y:thisBtn2.y+5});
TweenLite.to(thisBtn2.getChildByName(“bkg”), 1, {y:23,scaleY:.05, alpha:0, ease:Back.easeInOut, tint:0xFFFFFF});
navigateToURL (new URLRequest(“http://www.noeone.com”),”_blank”);
//navigateToURL (new URLRequest(links[thisOne]),”_blank”);

}

// CUSTOMIZE RIGHT CLICK CONTEXT MENU
var menu:ContextMenu = new ContextMenu();
menu.hideBuiltInItems();
var signature = new ContextMenuItem(“//NO3ONE//”);
signature.addEventListener (ContextMenuEvent.MENU_ITEM_SELECT, openLink);
function openLink (e:ContextMenuEvent):void {
navigateToURL (new URLRequest(“http://www.noeone.com”));
}
menu.customItems.push (signature);
contextMenu = menu;

TweenLite.to(mHolder, 1, {x: (stage.stageWidth – mHolder.width) / 2, delay: .25, ease:Back.easeInOut});

Download the FLA

Leave a Reply

visit my other website here >> noeone
Entries RSS Comments RSS Log in