2011-10-05 108 views
0

我知道这个问题会有一个简单明显的答案,但我已经花了两天,现在试图做没有运气(我是一个Flex新手) 基本上我试图打开一个webView,将打开谷歌地图到一个数组中的位置添加数组到URL字符串

该位置来自从facebook事件(这工作正常,将显示数据)数组中的数据,但我很努力将此信息传递给webView。 loadURL字符串

我想在数组中的数据是'data.location'(我有问题的代码是在代码片段底部的itemrenderer中)

我已经尝试了许多不同的选择,现在我被困

<?xml version="1.0" encoding="utf-8"?> 
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     title="Home" creationComplete="onLoad()"> 
<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"; 
    } 
]]> 
</fx:Script> 

    <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='+ "{data.location}") 
          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}"/> 
          <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> 
    <s:Label visible="false" x="6" id="NotLogin" width="463" height="78" styleName="text" 
      text="Sorry You Need To Be Logged In Via Facebook, Please Go Back and Log In, THANK YOU"/> 

回答

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)"/>