如何创建“仪表栏”在闪存中?

发布于 2024-09-15 18:56:57 字数 296 浏览 1 评论 0原文

我正在尝试在 Flash 中创建一个“仪表栏”。我正在 Flash 中创建一个交互式房屋。房子里面有消耗电力的物体。 (即灯泡、计算机、炉子等...)这些对象是切换按钮(使用 MovieClips 创建)。 (这些对象可以打开/关闭。)打开时 - 每个房屋对象都有一个关联的“功率值”(灯泡为 1,计算机为 2,电视为 3...)

我是尝试创建一个“仪表栏”(看起来像预加载栏),直观地显示房屋中正在使用的电量。拥有一米长的酒吧——意味着所有的屋内物品都被打开。

不知道从哪里开始。任何有关方向的想法或您可能认为有帮助的任何教程/示例将不胜感激。

I am trying to create a "meter bar" in Flash. I am creating an interactive house in Flash. Inside the house are objects that consume power. (ie. light bulb, computer, stove, etc...) Those objects are toggle buttons (created using MovieClips). (The objects can be toggled ON/OFF.) When ON--there is a "power value" associated with each house object (light bulb would be 1, computer would be 2, the tv would be 3...)

I am trying to create a "meter bar" (that looks like a preloader bar) that visually shows how much power in the house is being used. Having a full meter bar--would be having all the house objects turned on.

Not sure where to start. Any ideas as far as direction or any tutorials/examples you might find helpful would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光沙漏 2024-09-22 18:56:57

您可以创建一个自定义事件,每次单击某个项目时都会调度该事件。该事件有两个属性:功率级别和状态属性。

收到此事件后,您可以更新仪表栏的值。如果状态值为“Off”,则将仪表条值减少功率值,如果状态值为“On”,则增加功率值。

我会创建两个类
- ToggleClickButton ,将有一个每次点击都会更新的状态属性
- CustomEvent,如上所述

当然您必须添加缺少的元素(meterLevel,meterBar等...)

如果这一切都发生在同一个类中,则可以避免CustomEvent,在这种情况下您只需要知道单击的按钮状态并将其传递给具有 powerData 值的函数。

function toggleClick(event:MouseEvent):void
{
   var button:ToggleClickButton = event.currentTarget as ToggleClickButton;
   dispatchEvent( new CustomEvent( powerData ,  button.status) );
}

function customEventListener(event:CustomEvent ):void
{
   if( event.status == 0 )
  {
      meterLevel -= event.powerData;
  }else {

     meterLevel += event.powerData;
   }

   updateMeterDisplay();
}

function updateMeterDisplay()
{
   //for instance if you have a maxPower and a meterBar maxHeight
   meterBar.height = meterLevel * (maxHeight/maxPower );
}

You could create a custom event that would be dispatched each time an item is clicked. The event would have two properties, the power level and a status property.

When this event is received, you can update the value of your meter bar. if the status value is "Off" , decrement the meter bar value by the value of power , if "On" , increment by the value of power.

I would create two classes
- ToggleClickButton , would have a status property that is updated by each click
- CustomEvent , as explained above

Of course you have to add the missing elements ( meterLevel , meterBar etc... )

The CustomEvent can be avoided if it all happens within the same class , in such case you just need to know the clicked button status and pass this to a function with the powerData value.

function toggleClick(event:MouseEvent):void
{
   var button:ToggleClickButton = event.currentTarget as ToggleClickButton;
   dispatchEvent( new CustomEvent( powerData ,  button.status) );
}

function customEventListener(event:CustomEvent ):void
{
   if( event.status == 0 )
  {
      meterLevel -= event.powerData;
  }else {

     meterLevel += event.powerData;
   }

   updateMeterDisplay();
}

function updateMeterDisplay()
{
   //for instance if you have a maxPower and a meterBar maxHeight
   meterBar.height = meterLevel * (maxHeight/maxPower );
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文