我目前正在使用 Flashbuilder 4.6 创建移动应用程序,我希望根据用户选择的菜单项将用户推送到视图。下面的代码显示了我如何尝试将选定列表项中的字符串转换为类对象,然后将其传递给 pushView 的参数:
<fx:Script>
<![CDATA[
import mx.collections.*;
import spark.components.SplitViewNavigator;
import spark.components.ViewNavigator;
import spark.events.IndexChangeEvent;
import spark.events.ViewNavigatorEvent;
import spark.managers.PersistenceManager;
import spark.skins.mobile.SplitViewNavigatorSkin;
public var menuAC:ArrayCollection;
public var j_array:Array = [{label:"Home", data:"NLView"},
{label:"All Jobs", data:"JList"},
{label:"Company Profiles", data:"SView"},
{label:"Search By Sector", data:"JView"}];
protected function list_changeHandler(event:IndexChangeEvent):void
{
var selectedItem:String = new String(list.selectedItem.data);
//trace("Selected Item = " + selectedItem);
var splitNavigator:SplitViewNavigator = navigator.parentNavigator as SplitViewNavigator;
var detailNavigator:ViewNavigator = splitNavigator.getViewNavigatorAt(0) as ViewNavigator;
splitNavigator.hideViewNavigatorPopUp();
if(list.selectedItem.data == "NewListView")
{
var myClass:Class = getDefinitionByName(selectedItem) as Class;
trace("View Class = " + myClass);
detailNavigator.pushView(myClass);
}
else if(list.selectedItem.data)
{
}
}
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
if(data.view == "JSFilt")
{
menuAC = new ArrayCollection(j_array);
}
list.dataProvider = menuAC;
// TODO Auto-generated method stub
var splitNavigator:SplitViewNavigator = navigator.parentNavigator as SplitViewNavigator;
var detailNavigator:ViewNavigator = splitNavigator.getViewNavigatorAt(1) as ViewNavigator;
splitNavigator.hideViewNavigatorPopUp();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:BitmapImage width="100%" height="100%" source="@Embed('assets/images/sidebg.png')" fillMode="repeat"/>
<s:BitmapImage horizontalCenter="0" top="5" width="175" height="130" source="@Embed('assets/images/G_S_Logo_170x130.png')"/>
<s:List id="list" left="0" right="0"
color="0xFFFFFF" contentBackgroundColor="0x101010"
fontSize="20" width="280"
alternatingItemColors="[0x202020,0x2a2a2a]"
top="140" horizontalCenter="0" bottom="200"
downColor="0x70B2EE"
selectionColor="0x70B2EE"
change="list_changeHandler(event)">
<s:itemRenderer>
<fx:Component>
<s:IconItemRenderer messageStyleName="myFontStyle" fontSize="22" height="70"
labelField="label"
messageField=""
/>
</fx:Component>
</s:itemRenderer>
</s:List>
我也尝试过使用以下命令,但也没有用:
var viewClass:Class = Class(getDefinitionByName(getQualifiedClassName(selectedItem)));
有没有人知道如何查看列表中选择的值,然后使用该字符串名称将应用程序推送到视图,因为 pushView 方法不接受字符串?
感谢您的建议,我喜欢将类添加到数组然后将其传递给 pushView 的想法。我过去曾尝试过,但它没有用,所以我用下面的代码尝试了你的方法:
public var jobs_array:Array = [{label:"Home", data:"NewListView", class:NewListView},
{label:"All", data:"JList"},
{label:"C Prof's", data:"SView"},
{label:"S By S", data:"JSView"}];
如您所见,我已尝试实施您在第一行建议的内容,但出现以下错误:
1084: Syntax error: expecting colon before rightbrace.
1084: Syntax error: expecting identifier before class.
1084: Syntax error: expecting identifier before rightbrace.
这必须是一个简单的语法,但我看不到,有人可以帮我吗?