0

バックエンド用のアプリエンジンとフロントエンド用のflex 4でpythonとwebappフレームワークを使用しています。文字列形式のバックエンドをフロントエンドに渡したいので、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'];

ただし、null 値を受け取ります。

直し方アドバイスお願いします。ありがとう。

編集:2月25日

私の質問に答えてくれた人々に感謝します。私の質問では、swf ファイルを含む html ファイルをレンダリングするときに、python アプリ エンジンがフレックス アプリにデータを渡す方法を理解しようとしています。おそらく、私の仕事をするために main.py、swfobject.js、または index.html に設定できるものがあります。

Pyamf をゲートウェイとして使用してフレックス アプリを提供する方法を知っています。アプリをよりシンプルにする方法を考えています。

ありがとう。

編集:2月28日

ロバートさん、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", "display:block;text-align:left;");

このページを表示するには、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>  

ありがとう、ロバート。

編集:3月7日

ロバート、

http://help.adobe.com/en_US/Flex/4.0/html/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.htmlを参照してください。

ここに質問を投稿する前に、次のコードを試しました。

index.html では、

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

そしてまた

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

結果、私は得る:

< ユーザー

なぜ正しいデータを取得できないのか知っていますか。ありがとう。

4

3 に答える 3

2

FlexからGAEに話しかける最良の方法は、AMFを使用することです。方法は次のとおりです。

app.yaml

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

handlers:
- url: /services/.*
  script: 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コード(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>
于 2010-02-22T15:45:59.010 に答える
1

あなたのindex.htmlには何がありますか? 値を index.html に渡し、次のような JavaScript 関数を設定できます。

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

次に、Flex で関数を設定します。

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

でこれら 2 つの関数をコールバックします。

ExternalInterface.addCallback("PassParameter", gethtmlparam);

それが役立つことを願っています。

于 2010-02-25T00:09:10.087 に答える
1

James Ward の回答に対するあなたのコメントに基づいて、FlashVars param 要素で必要なことを達成できるかどうか疑問に思いますか?

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

FlashVars param 要素を作成するには、おそらく index.html テンプレートを調整するだけで済みます。

編集:3月6日

あなたは見てみるかもしれません: http://polygeek.com/801_flex_reading-flashvars-in-flex

flashVars にアクセスするには、アプリが読み込まれるまで待つ必要があります。

編集:3月7日

これらの例では、値をハードコーディングしています。値がテンプレート パラメーターの値に設定されるように、テンプレートを編集する必要があります。

したがって、index.html では次のようになります。 flashvars.userVO = "{{ userVO }}"

于 2010-02-26T16:20:31.800 に答える