我基於ActiveTuts的教程製作網站。基於Flash AS3的網站 - 爲每個菜單添加不同的顏色
這裏是我的代碼:
var navArray:Array=["HOME", "WORK", "MOVIES", "ABOUT", "CONTACT"];
for (var i:Number=0; i<4; i++) {
var navItem:NavItem=new NavItem ;
navItem.x=navItem.width*i;
navItem.nav_name.text=navArray[i];
buttonArray.push(navItem);
navItem.addListeners();
navContainer.addChild(navItem);
navItem.name=String(i);
navItem.addEventListener(MouseEvent.CLICK, onNavClick);
}
我想提出一個顏色的每個菜單上。
http://active.tutsplus.com/tutorials/web-design/create-a-full-screen-scalable-flash-website-part-1/
它在第二個視頻。
這裏是我的完整代碼:
// INITIAL VARIABLES
var buttonArray:Array = new Array();
var currentButton:Object=new Object ;
// ADD NAVIGATION CONTAINER
var navContainer:Sprite=new Sprite ;
addChild(navContainer);
// NAMES OF BUTTONS
var navArray:Array=["HOME", "WORK", "MOVIES", "ABOUT", "CONTACT"];
// ADD ALL THE BUTTONS WITH A FOR LOOP
for (var i:Number=0; i<5; i++) {
var navItem:NavItem=new NavItem ;
navItem.x=navItem.width*i;
navItem.nav_name.text=navArray[i];
buttonArray.push(navItem);
navItem.addListeners();
navContainer.addChild(navItem);
navItem.name=String(i);
navItem.addEventListener(MouseEvent.CLICK, onNavClick);
}
function onNavClick(evt:MouseEvent):void {
// PREVIOUS BUTTON
currentButton.y = 0;
currentButton.addListeners();
currentButton.addEventListener(MouseEvent.CLICK, onNavClick);
// NEXT BUTTON
currentButton = evt.target;
currentButton.removeListeners();
currentButton.removeEventListener(MouseEvent.CLICK, onNavClick);
}
// INITIAL STATE OF NAVIGATION
initialNavigation();
function initialNavigation():void {
buttonArray[0].y=-10;
currentButton=buttonArray[0];
currentButton.removeListeners();
currentButton.removeEventListener(MouseEvent.CLICK, onNavClick);
}
現在navItem代碼:
// FORMAT TEXTFIELD
nav_name.autoSize=TextFieldAutoSize.LEFT;
nav_name.selectable=false;
// POSITION TEXT ACCORDING TO IT'S WIDTH
nav_name.x=224-nav_name.width-15;
nav_name.mouseEnabled=false;
// ROLL OVER
function onOver(evt:MouseEvent):void {
TweenLite.to(this, 0.2, { y:-10});
trace("OVER");
}
function onOut(evt:MouseEvent):void {
TweenLite.to(this, 0.2, { y:0});
}
function addListeners():void {
this.addEventListener(MouseEvent.ROLL_OVER, onOver);
this.addEventListener(MouseEvent.ROLL_OUT, onOut);
}
function removeListeners():void {
this.removeEventListener(MouseEvent.ROLL_OVER, onOver);
this.removeEventListener(MouseEvent.ROLL_OUT, onOut);
}
我嘗試做這樣CGA說,這是確定的顏色,但現在我的「addlisteners」沒有按不再工作
您可以發佈您NavItem代碼?如果您也鏈接到教程,可能會很有用。 – 2013-04-03 23:25:52
http://active.tutsplus.com/tutorials/web-design/create-a-full-screen-scalable-flash-website-part-1/ 它在第二個視頻中。 – john 2013-04-06 09:04:06