一旦你創建了所有的城市圖標,並將它們放置在舞臺上並給予它們實例名稱,然後將它們放入一個數組中。這只是爲了讓事情更容易管理。
cityIcons.push(state_tx), cityIcons.push(state_ca)
等
現在,我們需要添加代碼來獲取氣球顯現。你提到了它的動畫效果。將你的氣球的動畫放在你的textfields下的cityTag_mc中。給它一個實例名稱,例如balloon_mc。
現在我們需要添加監聽器。我們將遍歷我們的數組,所以我們只需要編寫一次。
//instead of manually adding to listeners to every city icon movielip we can now
//just loop over all the items in the array
for (var i:int = 0; i < cityIcons.length;i++)
{
var mcCity:MovieClip = cityIcons[i] as MovieClip;
myCity.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver)
myCity.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut)
}
function onMouseOut(e:MouseEvent):void
{
cityTag_mc.visible = false;
//TODO any animating of balloon, maybe you could have
//different labels so instead of changing visible change alpha when your tweening
}
function onMouseOver(e:MouseEvent):void
{
//move balloon to where the city icon is
//e.target refers to the object you have added the listener to
cityTag_mc.x = e.target.x; // move the balloons position to the city's position
cityTag_mc.x = e.target.y;
//you may want to add an offset so its not directly overthe top
cityTag_mc.visible = true;
switch(e.target)
{
//testing which city instance icon we rolled over
case:state_tx
cityTag_mc.title_txt.text ="Texas";
cityTag_mc.balloon_mc.play(); //don't worry about this for now
//do remaining stuff
break;
case:state_ca
//same as above
}
}
您可以將稱爲cityTag_mc氣球的實例已經在舞臺上,並設置明顯的虛假,也可以根據需要創建和刪除。這只是一個指導,不要把它當作100%,因爲這只是我的頭頂。
我只是不能這樣做。我花了幾個小時,沒有得到任何地方。我甚至不知道從哪裏開始。感謝您的幫助,但這是無望的。 – dhornbein 2009-10-23 18:30:02
好吧,也許暫時不要擔心任何動畫只是基本的嘗試。創建一個代表城市的MovieClip圖標。將其中12個放在舞臺上,並給他們實例名稱。現在製作一個氣球的影片剪輯,裏面有兩個動態(非靜態)文本框,確保它們和氣球有實例名稱。在第一幀中使用ActionScript創建一個數組,然後像上面那樣將圖標推入數組中。然後使用我的上面的代碼替換任何實例名稱來匹配你的。現在忽略play()的東西。 – Allan 2009-10-24 01:13:33