0

我有一张美国地图,上面有许多城市(大约 12 个)的图标。当用户将鼠标悬停在其中一个图标上时,会在图标上弹出一个带有两个动态文本字段的影片剪辑。

每个城市的图标影片剪辑都以其所在州命名:state_(abbreviation)即:state_TX

弹出的文本气球被命名为:cityTag_mc 里面是两个动态文本字段:title_txt&subTitle_txt

逻辑是cityTag_mc当用户悬停state_TX并输入该状态的标题和子标题时添加。

我的主要问题是如何将文本输入字段(并为气球设置动画)。我不知道从哪里开始。我只想为动作脚本中的每个状态设置文本。我从哪说起呢?最佳做法是什么?

4

1 回答 1

0

一旦你创建了所有的城市图标并将它们放在舞台上并给它们实例名称,然后将它们放在一个数组中。这只是为了让事情更容易管理。

cityIcons.push(state_tx), cityIcons.push(state_ca)ETC

现在我们需要添加代码来显示气球。您也提到了对其进行动画处理。将在 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 的气球实例并将可见设置为 false,或者您可以根据需要创建和删除。这只是一个指南,不要把它当作 100%,因为这只是我的想法。

于 2009-10-23T00:12:45.083 回答