2009-10-10 64 views
0

我很害怕AS3。我已經嘗試了許多不同方式的這種效果。我試圖在AS3中得到一個導航條,做這樣的事情。Flash AS3流體導航條

A | B | C | d

點擊基於C欄的幻燈片,你會得到

Ç| A | B | d

點擊d欄幻燈片,你會得到

D | A | B | C

等等。

幫助或鏈接幫助非常感謝。現在我有這麼多。

david_btn.addEventListener(MouseEvent.CLICK, menuNav); 
kate_btn.addEventListener(MouseEvent.CLICK, menuNav); 
robin_btn.addEventListener(MouseEvent.CLICK, menuNav); 
aaron_btn.addEventListener(MouseEvent.CLICK, menuNav); 
ken_btn.addEventListener(MouseEvent.CLICK, menuNav); 
ann_btn.addEventListener(MouseEvent.CLICK, menuNav); 

function menuNav(event:MouseEvent):void { 
gotoAndStop(event.target.name); 
} 

每個去動畫片段,播放中途停止。現在我需要在下一個指定的標籤之前播放另一半。

+1

這個問題看起來很像「寫我的代碼給我」。似乎你並沒有完成任何工作。 – davr 2009-10-10 00:33:04

+0

如果您使用Flex,您可以輕鬆地使用HBox來做 - 只需更改子指數。在閃光燈中,我沒有意識到有這樣做的任何API控件。你必須自己寫。 – Amarghosh 2009-10-10 10:01:49

回答

1

喜的事情已經實現了。它也有一些額外的檢查/配置等。

//these are your button instances 
var originalOrder:Array = [tom, dick, harry, jane]; 

//this is a reference to the currently selected item 
var selectedItem:MovieClip = tom; 

//these are the co-ordinates of where the first item should be placed 
var offsetX:Number = 100; 
var offsetY:Number = 100; 

//this is how much padding you want between items 
var padding:Number = 8; 

addEventListener(MouseEvent.CLICK, mouseClickHandler); 

private function mouseClickHandler(e:Event):void 
{ 
    var index:int = originalOrder.indexOf(e.target); 
    //if the thing have clicked is in our array of buttons it is valid, we 
    //could have clicked something else interactive 
    if(index > -1) 
    { 
     //update the reference to the newly selected item 
     selectedItem = originalOrder[index]; 
     //move the items about 
     calculatePlacement(); 
    } 
} 


private function calculatePlacement():void 
{ 
    //we want to start with our x-position being the current offset 
    //plus the selectedItem's width plus the padding 
    var cumlativeWidth:Number = offsetX + selectedItem.width + padding; 
    var item:MovieClip; 

    //loop over all the items in our list in the order they are specified 
    for(var i:int = 0; i<originalOrder.length; i++) 
    { 
     //assign item to the currently looped item 
     item = originalOrder[i]; 
     //if the item we are looking at is the selected item, place it at the 
     //offset position 
     if(item == selectedItem) 
     { 
      item.x = offsetX; 
      item.y = offsetY; 
      //We could tween using Tweener/TweenLite 
      //TweenLite.to(item, 1, {x:offsetX, y:offsetY}); 
     } 
     //otherwise put it at our x-position, then add on its width + padding 
     //to the cumulative x-position. 
     else 
     { 
      item.x = cumlativeWidth; 
      item.y = offsetY; 
      //We could tween using Tweener/TweenLite 
      //TweenLite.to(item, 1, {x:offsetX, y:offsetY}); 
      cumlativeWidth += item.width + padding; 
     } 
    } 
} 
1

只要確保第一個按鈕的初始x位置是14或者您相應地調整了代碼。

例子在這裏,我已經給雅舍的回答加一個,因爲它服務的目的,但是,我只是要步行通過下面的代碼,這樣你可以瞭解這種http://www.hupcapstudios.com/slideNav.swf

import caurina.transitions.Tweener; 

var btnArray:Array = new Array(btn1,btn2,btn3,btn4); 
var btnNames:Array = new Array("Tom","Dick","Harry","Marco"); 

for(var i:int=0;i<btnArray.length;i++) 
{ 
    btnArray[i].btn_txt.text = btnNames[i]; 
    btnArray[i].addEventListener(MouseEvent.CLICK, slideBtn); 
} 

function slideBtn(e:Event):void 
{ 
    var aPos:Number = e.currentTarget.x; 
    var bPos:Number; 
    var zeroBtn:*; 

    trace(aPos); 

    if(aPos !== 14) 
    { 
     for(var p:int = 0;p<btnArray.length;p++) 
     { 
      if(btnArray[p].x == aPos) 
      { 
       bPos = aPos; 
       break; 
      } 
     } 
     for(var q:int = 0;q<btnArray.length;q++) 
     { 
      if(btnArray[q].x == 14) 
      { 
       zeroBtn = btnArray[q]; 
       break; 
      } 
     } 

     Tweener.addTween(e.currentTarget, {x:14, time:.4,transition:"easeOutQuint"}); 
     Tweener.addTween(zeroBtn, {x:bPos, time:.4,transition:"easeOutQuint"}); 
    } 
} 
+0

感謝球員們花時間幫助我。我想我已經得到了它,或者至少你讓我有一個好點,我可以從這裏解決問題。 – defawlt 2009-10-13 21:16:58