代码之家  ›  专栏  ›  技术社区  ›  michael

如何将数据从google app engine(python)传递到flex 4应用程序

  •  0
  • michael  · 技术社区  · 15 年前

    我在后端应用引擎中使用python和webapp框架,在前端使用flex 4。 我想将字符串形式的后端传递到前端,所以我在main.py中编写了以下代码:

    类主页(webapp.requesthandler):
    
    DEF get(自):
    
    USEVO =“测试”
    
    模板值={
    “url”:self.request.uri,
    “uservo”:用户vo,
    
    }
    self.response.out.write(template.render(“templates/index.html”,template_values))。
    < /代码> 
    
    

    在flex 4中,我有以下代码:

    var user:string=flexglobals.toplevellapplication.parameters['uservo'];
    < /代码> 
    
    

    但是,我收到空值。

    请建议如何更正。谢谢,

    编辑:2月25日。

    谢谢那些回答我问题的人。对于我的问题,我试图弄清楚当python应用引擎呈现包含swf文件的HTML文件时,它是如何将数据传递给flex应用程序的。也许,我可以在main.py、swfobt.js或index.html中设置一些内容来完成我的任务。

    我知道如何使用pyamf作为为flex应用程序提供服务的网关,我正在考虑如何使应用程序更简单。

    谢谢。< / P>

    编辑:2月28日。

    robert,index.html是FlashBuilder4创建的标准文件。希望你能给我一些提示如何修改它。文件如下:

    <!doctype html public”-//w3c//dtd xhtml 1.0 transitional//en“”http://www.w3.org/tr/xhtml 1/dtd/xhtml 1 transitional.dtd“>
    &!--保存自url=(0014)关于:internet-->
    
    <html xmlns=“http://www.w3.org/1999/xhtml”lang=“en”xml:lang=“en”>
    &!——
    聪明的开发人员总是查看源代码。
    
    此应用程序是使用开放源代码框架AdobeFlex构建的。
    用于构建通过
    Flash播放器或通过Adobe Air连接到桌面。
    
    有关flex的更多信息,请访问http://flex.org。
    //-gt;
    &头;
    <标题></title>
    <meta http equiv=“content type”content=“text/html;charset=iso-8859-1”/>
    

    HTML,主体高度:100%; 正文边距:0;填充:0;溢出:隐藏;文本对齐:居中;
    #FlashContent显示:无;

    <script type=“text/javascript”src=“/js/swfobject.js”></script>
    <script type=“text/javascript”>
    &!--对于版本检测,设置为最低要求的Flash播放器版本,或0(或0.0.0),不进行版本检测。---GT;
    var swfversionstr=“10.0.0”;
    <!--要使用Express安装,请设置为playerProductInstall.swf,否则设置为空字符串。-->
    var xiswburlstr=“/swfs/playerproductinstall.swf”;
    var flashvars=
    var参数=
    params.quality=“高”;
    params.bgcolor=“ffffff”;
    params.allowscriptsaccess=“samedomain”;
    var属性=
    attributes.id=“索引”;
    attributes.name=“索引”;
    attributes.align=“中间”;
    嵌入对象(
    “/swfs/index.swf”,“FlashContent”,
    “100%”,“100%”,
    SWFversionStr、XiswFlurlstr和
    flashvars、params、attributes);
    < /代码> 
    
    

    swfobject.createcss(“flashContent”,“display:block;text-align:left;”);

    要查看此页面,请确保Adobe Flash Player版本 安装10.0.0或更高版本。

    <noscript>
    <object classid=“clsid:d27cdb6e-ae6d-11cf-96b8-444553540000”width=“100%”height=“100%”id=“index”>
    <param name=“movie”value=“index.swf”/>
    <param name=“Quality”value=“high”/>
    <param name=“bgcolor”value=“ffffff”/>
    <param name=“allowscriptAccess”value=“samedomain”/>
    &!——如果!IE;
    <object type=“application/x-shockwave-flash”data=“index.swf”width=“100%”height=“100%”>
    <param name=“Quality”value=“high”/>
    <param name=“bgcolor”value=“ffffff”/>
    <param name=“allowscriptAccess”value=“samedomain”/>
    &![Endof ] -gt;
    &!--[如果GTE IE 6]>
    & P & GT;
    脚本和活动内容不允许运行或Adobe Flash Player版本
    未安装10.0.0或更高版本。
    & lt;/p & gt;
    &![Endof ] -gt;
    <a href=“http://www.adobe.com/go/getflashplayer”>
    <img src=“https://www.adobe.com/images/shared/download_buttons/get_flash_player.gif”alt=“get adobe flash player”/>gt;
    & lt;/a & gt;
    &!——如果!IE;
    </object>
    &![Endof ] -gt;
    </object>
    </noscript>
    < /代码> 
    
    

    谢谢,罗伯特。

    编辑:3月7日。

    <>罗伯特,

    请参阅http://help.adobe.com/en_us/flex/4.0/html/ws2db454920e96a9e51e63e3d11c0bf626ae-7feb.html“rel=”nofollow noreferrer“>http://help.adobe.com/en_us/flex/4.0/html/ws2db454920e96a9e51e63e3d11c0bf626ae-7feb.html

    在我在这里发布问题之前,我尝试了以下代码:

    在index.html中,

    <%
    string user=(string)请求.getParameter(“uservo”);
    %& gt;
    < /代码> 
    
    

    以及

    flashvars.uservo=“<%=user%>”;
    < /代码> 
    
    

    结果,我得到:

    <用户

    你知道我为什么不能得到正确的数据吗?谢谢。

    class MainPage(webapp.RequestHandler):
    
     def get(self):
    
      userVO = "test"
    
      template_values = {
       'url': self.request.uri,
       'userVO': userVO,
    
      }
      self.response.out.write(template.render("templates/index.html", template_values))
    

    在flex 4中,我有以下代码:

    var user:String = FlexGlobals.topLevelApplication.parameters['userVO'];
    

    但是,我收到空值。

    请建议如何更正。谢谢。

    编辑:25月2日。

    谢谢那些回答我问题的人。对于我的问题,我试图弄清楚当python应用引擎呈现包含swf文件的HTML文件时,它是如何将数据传递给flex应用程序的。也许,我可以在main.py、swfobt.js或index.html中设置一些内容来完成我的任务。

    我知道如何使用pyamf作为为flex应用提供服务的网关,我正在思考如何使应用更简单。

    谢谢。

    编辑:2月28日

    robert,index.html是FlashBuilder4创建的标准文件。希望你能给我一些提示如何修改它。文件如下:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <!-- saved from url=(0014)about:internet -->  
    
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> 
    <!-- 
    Smart developers always View Source. 
    
    This application was built using Adobe Flex, an open source framework
    for building rich Internet applications that get delivered via the
    Flash Player or to desktops via Adobe AIR. 
    
    Learn more about Flex at http://flex.org 
    // -->
       <head>
       <title></title>         
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    

    HTML,主体高度:100%; 正文边距:0;填充:0;溢出:隐藏;文本对齐:居中;
    #FlashContent显示:无;

        <script type="text/javascript" src="/js/swfobject.js"></script>
        <script type="text/javascript">
            <!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. --> 
            var swfVersionStr = "10.0.0";
            <!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
            var xiSwfUrlStr = "/swfs/playerProductInstall.swf";
            var flashvars = {};
            var params = {};
            params.quality = "high";
            params.bgcolor = "#ffffff";
            params.allowscriptaccess = "sameDomain";
            var attributes = {};
            attributes.id = "index";
            attributes.name = "index";
            attributes.align = "middle";
            swfobject.embedSWF(
                "/swfs/index.swf", "flashContent", 
                "100%", "100%", 
                swfVersionStr, xiSwfUrlStr, 
                flashvars, params, attributes);
    

    swfobject.createcss(“flashContent”,“display:block;text-align:left;”);

    要查看此页面,请确保Adobe Flash Player版本 安装10.0.0或更高版本。

    Get Adobe Flash Player
        <noscript>
            <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" id="index">
                <param name="movie" value="index.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="allowScriptAccess" value="sameDomain" />
                <!--[if !IE]>
                <object type="application/x-shockwave-flash" data="index.swf" width="100%" height="100%">
                    <param name="quality" value="high" />
                    <param name="bgcolor" value="#ffffff" />
                    <param name="allowScriptAccess" value="sameDomain" />
                <![endif]-->
                <!--[if gte IE 6]>
                 <p> 
                  Either scripts and active content are not permitted to run or Adobe Flash Player version
                  10.0.0 or greater is not installed.
                 </p>
                <![endif]-->
                    <a href="http://www.adobe.com/go/getflashplayer">
                        <img src="https://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" />
                    </a>
                <!--[if !IE]>
                </object>
                <![endif]-->
            </object>
     </noscript>  
    

    谢谢,罗伯特。

    编辑:7 MAR.

    罗伯特

    参照http://help.adobe.com/en_US/Flex/4.0/html/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html

    在我在这里发布问题之前,我尝试了以下代码:

    在index.html中,

    <%
         String user = (String) request.getParameter("userVO");
    %>
    

    而且

    flashvars.userVO =  "<%= user %>"; 
    

    结果,我得到:

    <用户

    你知道我为什么不能得到正确的数据吗?谢谢。

    3 回复  |  直到 15 年前
        2
  •  2
  •   James Ward    15 年前

    application: flexandthecloud
    version: 3
    runtime: python
    api_version: 1
    
    handlers:
    - url: /services/.*
      script: main.py
    

    #!/usr/bin/env python
    import wsgiref.handlers
    
    from pyamf.remoting.gateway.wsgi import WSGIGateway
    
    def sayHello(name):
      return "howdy " + name
    
    services = {
        'services.sayHello': sayHello
    }
    
    def main():
      application = WSGIGateway(services)
      wsgiref.handlers.CGIHandler().run(application)
    
    if __name__ == '__main__':
      main()
    

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    
        <mx:RemoteObject id="ro" destination="services" endpoint="http://flexandthecloud.appspot.com/services/">
            <mx:result>
                l.text = event.result as String;
            </mx:result>
        </mx:RemoteObject>
    
        <mx:TextInput id="ti"/>
        <mx:Label id="l"/>
        <mx:Button label="say hello" click="ro.sayHello(ti.text)"/>
    
    </mx:Application>
    
        3
  •  1
  •   mal39    15 年前

    function passvalue {
        PassParameter("userVO", "{{userVO}}");
    }
    

    public function gethtmlparam(name:String, val:String):void {
                switch (name) {
                    case "userVO": userVO= val; break;}
    }
    

    ExternalInterface.addCallback("PassParameter", gethtmlparam);
    

    推荐文章