我有一个应用程序,当前从Facebook获取事件数据并将其显示在列表中
<s:List id="eventsDataGrid" width="100%" height="100%" dataProvider="{facebookEvents}">
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<fx:Script>
<![CDATA[
import com.facebook.graph.utils.FacebookDataUtils;
private function time2DateStr(time:String):String {
return FacebookDataUtils.stringToDate(time).toLocaleString();
}
]]>
</fx:Script>
<s:HGroup paddingBottom="10" paddingTop="10">
<s:Image source="{data.pic}"/>
<s:VGroup width="100%">
<s:Label text="{data.name}" fontWeight="bold" width="100%"/>
<s:Label text="Where: {data.location}" id="locationtxt"/>
<s:Label text="When: {time2DateStr(data.start_time)}"/>
</s:VGroup>
</s:HGroup>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
我正在尝试添加一个按钮,该按钮将在webView中显示位置,但我无法让应用程序使用数组中的data.location将其用于Google地图(我只是添加data.location详细信息到谷歌地图URL的末尾,然后使用地图搜索该位置 我可以让按钮工作,但它不会搜索位置它只是在Flash构建器中显示错误(我假设是由于我没有正确地将数据添加到字符串)或搜索“data.location” 以下是将加载URL但没有位置的当前代码
<s:List id="eventsDataGrid" width="100%" height="100%" dataProvider="{facebookEvents}">
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<fx:Script>
<![CDATA[
import com.facebook.graph.utils.FacebookDataUtils;
var webView:StageWebView = new StageWebView
var mapURL:String = "http://maps.google.com/maps?f=d&hl=en&saddr="
private function time2DateStr(time:String):String {
return FacebookDataUtils.stringToDate(time).toLocaleString();
}
protected function getDirections_clickHandler(event:MouseEvent):void
{
webView.stage = this.stage;
webView.viewPort = new Rectangle(0, 100, stage.stageWidth, stage.stageHeight);
webView.loadURL(mapURL);
}
]]>
</fx:Script>
<s:HGroup paddingBottom="10" paddingTop="10">
<s:Image source="{data.pic}"/>
<s:VGroup width="100%">
<s:Label text="{data.name}" fontWeight="bold" width="100%"/>
<s:Label text="Where: {data.location}" id="locationtxt"/>
<s:Label text="When: {time2DateStr(data.start_time)}"/>
<s:Label text="Get Directions" click="getDirections_clickHandler(event)" id="getDirections"/>
</s:VGroup>
</s:HGroup>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
完整代码
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable] private var facebookEvents:ArrayCollection;
import com.facebook.graph.FacebookMobile;
private function onLoad():void
{
if(FacebookMobile.getSession() != null) {
getEvents()
} else {
eventsDataGrid.visible=false
NotLogin.visible=true
}
}
private function getEvents():void {
var fql:String = "select name, location, pic, start_time from event where creator = 148839887036 and eid in (select eid from event_member where uid=148839887036)";
FacebookMobile.fqlQuery(fql, handleGetEventsResponse);
}
private function handleGetEventsResponse(events:Object, fail:Object):void {
if (events != null)
facebookEvents = new ArrayCollection(events as Array);
//else
//status = "Error";
}
]]>
<s:List id="eventsDataGrid" width="100%" height="100%" dataProvider="{facebookEvents}">
<s:itemRenderer>
<fx:Component>
<s:ItemRenderer>
<fx:Script>
<![CDATA[
import com.facebook.graph.utils.FacebookDataUtils;
var webView:StageWebView = new StageWebView
var mapURL:String = "http://maps.google.com/maps?f=d&hl=en&saddr="
private function time2DateStr(time:String):String {
return FacebookDataUtils.stringToDate(time).toLocaleString();
}
protected function getDirections_clickHandler(event:MouseEvent):void
{
webView.stage = this.stage;
webView.viewPort = new Rectangle(0, 100, stage.stageWidth, stage.stageHeight);
webView.loadURL(mapURL);
}
]]>
</fx:Script>
<s:HGroup paddingBottom="10" paddingTop="10">
<s:Image source="{data.pic}"/>
<s:VGroup width="100%">
<s:Label text="{data.name}" fontWeight="bold" width="100%"/>
<s:Label text="Where: {data.location}" id="locationtxt"/>
<s:Label text="When: {time2DateStr(data.start_time)}"/>
<s:Label text="Get Directions" click="getDirections_clickHandler(event)" id="getDirections"/>
</s:VGroup>
</s:HGroup>
</s:ItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>
答案 0 :(得分:0)
我需要做的就是将数据添加到括号中(不知道官方名称)这里是
protected function directions_click (location:String):void
{
navigateToURL(new URLRequest('http://maps.google.co.uk/maps?q=' + location));
}
和按钮/标签
<s:Label text="Get Directions" fontFamily="lucida grande" fontSize="14" color="#3b5998" click="directions_click(data.location)"/>