简体   繁体   English

如何将数据从Google App Engine(Python)传递到Flex 4应用程序

[英]How to pass data from Google App Engine(Python) to Flex 4 application

I am using python and webapp framework in app engine for backend and flex 4 for front end. 我在后端使用App Engine中的python和webapp框架,在前端使用flex 4。 I would like to pass a string form backend to front end, so i write the following code in the main.py: 我想将字符串形式的后端传递给前端,因此我在main.py中编写以下代码:

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

And in the flex 4, I have the following code: 在flex 4中,我有以下代码:

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

However, I receive null value. 但是,我收到空值。

Please advice how to correct it. 请建议如何纠正它。 Thanks. 谢谢。

Edit: 25 Feb. 编辑:2月25日。

Thanks for the people who answer my question. 感谢您回答我的问题的人。 For my question, I am try to figure out how the python app engine pass data to flex app when it render the html file that include the swf file. 对于我的问题,我试图弄清楚python应用程序引擎在呈现包含swf文件的html文件时如何将数据传递给flex应用程序。 Maybe, there is something I can set in the main.py, swfobject.js or the index.html to do my task. 也许可以在main.py,swfobject.js或index.html中设置一些内容来执行任务。

I know how to use Pyamf as a gateway to serve the flex app, I am thinking how to make the app more simple. 我知道如何使用Pyamf作为服务Flex应用程序的网关,我正在考虑如何使该应用程序更简单。

Thanks. 谢谢。

Edit: 28 Feb. 编辑:2月28日。

Robert, the index.html is the standard file created by flash builder 4. Wish you can give me some hints how to modify it. Robert,index.html是Flash Builder 4创建的标准文件。希望您能给我一些如何修改它的提示。 The following is the file: 以下是文件:

<!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, body { height:100%; html,正文{高度:100%; } body { margin:0; } body {margin:0; padding:0; 填充:0; overflow:hidden; 溢出:隐藏; text-align:center; 文本对齐:中心; } }
#flashContent { display:none; #flashContent {display:none; } }

    <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;"); swfobject.createCSS(“#flashContent”,“ display:block; text-align:left;”);

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed. 要查看此页面,请确保已安装Adobe Flash Player 10.0.0或更高版本。

获取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>  

Thanks, Robert. 谢谢,罗伯特。

Edit: 7 Mar. 编辑:3月7日。

Robert, 罗伯特,

Refer to http://help.adobe.com/en_US/Flex/4.0/html/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html 请参阅http://help.adobe.com/zh_CN/Flex/4.0/html/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html

Before I post the question here, I tried the following code: 在这里发布问题之前,我尝试了以下代码:

In the index.html, 在index.html中,

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

and also 并且

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

The result, I get: 结果,我得到:

< user <用户

Do you know why I can't get the correct data. 您知道我为什么无法获得正确的数据吗? Thanks. 谢谢。

The best way to talk from Flex to GAE is using AMF. 从Flex到GAE交流的最佳方法是使用AMF。 Here is how: 方法如下:

app.yaml 的app.yaml

application: flexandthecloud
version: 3
runtime: python
api_version: 1

handlers:
- url: /services/.*
  script: main.py

main.py 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()

Flex 3 code (can be easily modified for Flex 4): Flex 3代码(可以为Flex 4轻松修改):

<?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>

What's in your index.html? 您的index.html中有什么? You can pass the values to index.html, set a javascript function like: 您可以将值传递给index.html,设置javascript函数,例如:

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

Then set a function in Flex: 然后在Flex中设置一个函数:

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

and call back these two function in : 并在以下位置调用这两个函数:

ExternalInterface.addCallback("PassParameter", gethtmlparam);

Hope it can help. 希望能有所帮助。

Based on your comment to James Ward's response, I wonder if you can accomplish what you need with a FlashVars param element? 根据您对James Ward答复的评论,我想知道您是否可以使用FlashVars param元素完成所需的工作?

http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_3.html http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_3.html

You will probably just need to adjust the index.html template to build the FlashVars param element. 您可能只需要调整index.html模板即可构建FlashVars param元素。

Edit: 6 Mar 编辑:3月6日

You might try looking at: http://polygeek.com/801_flex_reading-flashvars-in-flex 您可以尝试查看: http : //polygeek.com/801_flex_reading-flashvars-in-flex

You need to be sure you wait until the app has been loaded to access the flashVars. 您需要确保等到加载应用程序后才能访问Flash变量。

Edit: 7 Mar 编辑:3月7日

Correct, in those examples they hard code the value. 正确,在这些示例中,他们将值硬编码。 You need to edit your template so the value is set to the value of the template parameter. 您需要编辑模板,以便将该值设置为template参数的值。

So, in index.html: flashvars.userVO = "{{ userVO }}" 因此,在index.html中: flashvars.userVO = "{{ userVO }}"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从桌面python应用程序访问App Engine数据模型? - How to access app engine data model from desktop python application? 如何在Google App Engine中更新数据-Python? - How to update data in google app engine - Python? 如何使用Google App Engine Python将变量从app.yaml传递到main.py. - How to pass a variable from app.yaml to main.py with Google App Engine Python 除了在 Google App Engine Flex 环境中部署 python flask 应用程序之外,还有其他替代方法吗? - Is there any alternative approach other than deploying python flask application in Google app engine flex environment? 如何将参数传递给部署在 Google App Engine 上的 Python 脚本? - How to pass a parameter to a python script deployed on Google App Engine? 如何在Google App Engine python中将多个参数传递给处理程序? - How to pass multiple arguments to handlers in Google App Engine python? 如何将变量数组/对象传递给python(Google App Engine) - how to pass a variable array/object to python (google app engine) Google App Engine: JAVA command not recognized by Python in Flex environment with Docker (`java` command is not found from this Python process) - Google App Engine: JAVA command not recognized by Python in Flex environment with Docker (`java` command is not found from this Python process) Google App引擎,Python和按值传递的对象 - Google app engine and python and objects that pass by value 如何使用Python在Google App Engine中使用应用程序部署映像 - How to Deploy an Image with the Application in Google App Engine Using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM