如何将数据从 Google App Engine(Python) 传递到 Flex 4 应用程序
我在应用程序引擎中使用 python 和 webapp 框架作为后端,使用 flex 4 作为前端。 我想将字符串形式后端传递到前端,所以我在 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))
在 Flex 4 中,我有以下代码:
var user:String = FlexGlobals.topLevelApplication.parameters['userVO'];
但是,我收到空值。
请指教如何纠正。谢谢。
编辑:2 月 25 日
感谢回答我问题的人。对于我的问题,我试图弄清楚Python应用程序引擎在渲染包含swf文件的html文件时如何将数据传递给flex应用程序。也许,我可以在 main.py、swfobject.js 或 index.html 中设置一些东西来完成我的任务。
我知道如何使用 Pyamf 作为网关来服务 Flex 应用程序,我正在考虑如何使应用程序更简单。
谢谢。
编辑:2月28日
Robert,index.html是flash builder 4创建的标准文件。希望你能给我一些如何修改它的提示。以下是该文件:
<!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", "显示:块;文本对齐:左;");
要查看此页面,请确保 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" />
<!--[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>
谢谢,罗伯特。
编辑:3 月 7 日
Robert,
请参阅 http://help.adobe.com/en_US/Flex/4.0/html/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html
在我在这里发布问题之前,我尝试了以下代码:
在index.html中,
<%
String user = (String) request.getParameter("userVO");
%>
并且还
flashvars.userVO = "<%= user %>";
结果,我得到:
< user
你知道为什么我无法获取正确的数据吗?谢谢。
I am using python and webapp framework in app engine for backend and flex 4 for front end.
I would like to pass a string form backend to front end, so i write the following code in the 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:
var user:String = FlexGlobals.topLevelApplication.parameters['userVO'];
However, I receive null value.
Please advice how to correct it. Thanks.
Edit: 25 Feb.
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. Maybe, there is something I can set in the main.py, swfobject.js or the index.html to do my task.
I know how to use Pyamf as a gateway to serve the flex app, I am thinking how to make the app more simple.
Thanks.
Edit: 28 Feb.
Robert, the index.html is the standard file created by flash builder 4. Wish you can give me some hints how to modify it. 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%; }
body { margin:0; padding:0; overflow:hidden; text-align:center; }
#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;");
To view this page ensure that Adobe Flash Player version
10.0.0 or greater is installed.
<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.
Robert,
Refer to http://help.adobe.com/en_US/Flex/4.0/html/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html
Before I post the question here, I tried the following code:
In the 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 Flex 与 GAE 对话的最佳方式是使用 AMF。方法如下:
app.yaml
main.py
Flex 3 代码(可以轻松修改为 Flex 4):
The best way to talk from Flex to GAE is using AMF. Here is how:
app.yaml
main.py
Flex 3 code (can be easily modified for Flex 4):
根据您对 James Ward 回复的评论,我想知道您是否可以使用 FlashVars param 元素来完成您需要的功能?
http://livedocs.adobe.com/flex/ 3/html/help.html?content=passingarguments_3.html
您可能只需要调整index.html 模板即可构建FlashVars param 元素。
编辑:3 月 6 日
您可以尝试查看:
http://polygeek.com/801_flex_reading-flashvars-in-flex
您需要请务必等到应用程序加载后才能访问 flashVars。
编辑:3 月 7 日
正确,在这些示例中,他们对值进行了硬编码。您需要编辑模板,以便将值设置为模板参数的值。
所以,在index.html中:
flashvars.userVO = "{{ userVO }}"
Based on your comment to James Ward's response, I wonder if you can accomplish what you need with a FlashVars param element?
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.
Edit: 6 Mar
You might try looking at:
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.
Edit: 7 Mar
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.
So, in index.html:
flashvars.userVO = "{{ userVO }}"
你的index.html中有什么?
您可以将值传递给index.html,设置一个javascript函数,例如:
然后在Flex中设置一个函数:
并在:中回调这两个函数
希望它能有所帮助。
What's in your index.html?
You can pass the values to index.html, set a javascript function like:
Then set a function in Flex:
and call back these two function in :
Hope it can help.