Flash AS3 中的 Astra TabBar 困难
除了能够传递我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有使用 Astra TabBar 的经验,但在我看来,您最初并没有调用您的 handleEvent() 函数。当您实例化您的类时,您需要为其添加一个侦听器。如果未调用handleEvent(),则永远不会添加点击侦听器,并且您将不会看到点击。
另外,我不确定您到底想做什么,但您似乎正在向您创建的每个 TabBar 实例添加一个新的 TabBar。
这里的关键字“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.
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.
The keyword "this" here would refer to your TabBar instance and may cause this class to infinitely add new TabBars to exisitng TabBars.