Flash AS3 中的 Astra TabBar 困难

发布于 2024-12-11 21:52:04 字数 1101 浏览 0 评论 0原文

除了能够传递我的 DataProvider 数组之外,我很难让 Astra TabBar 执行任何操作。我试图让它在单击选项卡时使用 CHANGE 事件简单地跟踪“单击”。什么也没发生,我不知道为什么。 请问有人有这方面的经验吗?我的代码如下所示:

package
{
import com.yahoo.astra.fl.controls.TabBar;
import com.yahoo.astra.fl.events.TabBarEvent;
public class TabBar extends Window
{
public var tabBarGpl:TabBar;
private function displayInit():void
{
var tabBarData:Array = new Array(
"Tab one",
"Tab two",
"Tab three",
"Tab four"
);
var tabBarGpl:TabBar = new TabBar();
tabBarGpl.dataProvider = new DataProvider(tabBarData);
tabBarGpl.selectedIndex = 0;
tabBarGpl.move(-230.95, -127.65);
this.addChild(tabBarGpl);
}
private function handleEvent(event:Event):void
{
var i:int;
switch (event.type)
{
case Event.ADDED_TO_STAGE :
displayInit();
removeEventListener(Event.ADDED_TO_STAGE, handleEvent);
addEventListener(Event.REMOVED_FROM_STAGE, handleEvent, false, 0, true);
this.tabBarGpl.addEventListener(Event.CHANGE, onTabBarClick);
}
}
private function onTabBArClick(event:Event):void
{
trace("tab bar clicked");
}
}
}

并且...什么也没有。我在 4 个选项卡上看到带有我的数据的 TabBar,但输出中没有跟踪语句。任何建议都会有帮助。谢谢你!

I am having a difficult time getting the Astra TabBar to do anything except be able to pass in my DataProvider array. I am trying to get it to simply trace a "click" using the CHANGE event when clicking on a tab. Nothing happens and I'm not sure why.
Does anyone have experience with this, please? My code looks like this:

package
{
import com.yahoo.astra.fl.controls.TabBar;
import com.yahoo.astra.fl.events.TabBarEvent;
public class TabBar extends Window
{
public var tabBarGpl:TabBar;
private function displayInit():void
{
var tabBarData:Array = new Array(
"Tab one",
"Tab two",
"Tab three",
"Tab four"
);
var tabBarGpl:TabBar = new TabBar();
tabBarGpl.dataProvider = new DataProvider(tabBarData);
tabBarGpl.selectedIndex = 0;
tabBarGpl.move(-230.95, -127.65);
this.addChild(tabBarGpl);
}
private function handleEvent(event:Event):void
{
var i:int;
switch (event.type)
{
case Event.ADDED_TO_STAGE :
displayInit();
removeEventListener(Event.ADDED_TO_STAGE, handleEvent);
addEventListener(Event.REMOVED_FROM_STAGE, handleEvent, false, 0, true);
this.tabBarGpl.addEventListener(Event.CHANGE, onTabBarClick);
}
}
private function onTabBArClick(event:Event):void
{
trace("tab bar clicked");
}
}
}

And... Nothing. I see the TabBar with my Data on the 4 tabs, but no trace statement in the output. Any advice would be helpful. Thank you!

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

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

发布评论

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

评论(1

2024-12-18 21:52:04

我没有使用 Astra TabBar 的经验,但在我看来,您最初并没有调用您的 handleEvent() 函数。当您实例化您的类时,您需要为其添加一个侦听器。如果未调用handleEvent(),则永远不会添加点击侦听器,并且您将不会看到点击。

public function TabBar() { //constructor function
    addEventListener(Event.ADDED_TO_STAGE, handleEvent);
}

另外,我不确定您到底想做什么,但您似乎正在向您创建的每个 TabBar 实例添加一个新的 TabBar。

var tabBarGpl:TabBar = new TabBar();
tabBarGpl.dataProvider = new DataProvider(tabBarData);
tabBarGpl.selectedIndex = 0;
tabBarGpl.move(-230.95, -127.65);
this.addChild(tabBarGpl);

这里的关键字“this”将引用您的 TabBar 实例,并可能导致此类无限地向现有 TabBar 添加新的 TabBar。

I don't have experience with Astra TabBar, but it looks to me like you're not calling your handleEvent() function initially. You need to add a listener for it when you instantiate your class. If handleEvent() doesn't get called, the click listener is never added and you won't see clicks.

public function TabBar() { //constructor function
    addEventListener(Event.ADDED_TO_STAGE, handleEvent);
}

Also, I'm not sure what you're trying to do exactly, but you seem to be adding a new TabBar to each instance of TabBar that you create.

var tabBarGpl:TabBar = new TabBar();
tabBarGpl.dataProvider = new DataProvider(tabBarData);
tabBarGpl.selectedIndex = 0;
tabBarGpl.move(-230.95, -127.65);
this.addChild(tabBarGpl);

The keyword "this" here would refer to your TabBar instance and may cause this class to infinitely add new TabBars to exisitng TabBars.

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