如何在外部mxml中访问html请求参数
我希望从 HTML 表单中启动现有的工作 Flex 应用程序,并传入参数 EG、登录详细信息。
假设我有一个简单的 HTML 页面,其中根本没有 FLASH。
<h1>Test sending parameters</h1>
<form name="login" action="http://example.com/myflexApp/index.html"
target="_new" method="POST">
username: <input type="text" name="username" />
password: <input type="text" name="password" />
<input type="submit" value="Submit" />
</form>
这将第一次在新的浏览器窗口中打开我的应用程序
我的index.mxml被编译以创建index.html,看起来像这样(简化的):
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
...
creationComplete="init(event)" xmlns:omp="omp.*">
<fx:Style source="defaults.css"/>
<fx:Script>
<![CDATA[
import ...
protected function init(event:FlexEvent):void
{
if (params[username] && params[password])//psuedo code
{
Alert.show(params[username],params[password]);//debugging
//login(params[username],params[password]);//psuedo code to log in automatically
}else{
//existing code to show login form which works
}
}
]]>
</fx:Script>
<mx:ViewStack id="vs" width="100%" height="100%" ...>
</mx:ViewStack>
</s:Application>
那么html代码应该是什么样子以及相应的actionscript代码是什么进入 init() 函数?
或者,至少我应该用谷歌搜索什么?
注意:显然,参数和值显示在浏览器的 URL 地址中是不可接受的。不然这事就容易了。
另请注意,该应用程序并未嵌入到原始 HTML 页面中,尽管我在该主题上找到的 99.9% 的搜索结果都给出了如果嵌入到原始 HTML 页面中该怎么做的示例。
理想情况下,原始请求是 POST 请求,但显然 Flex 无法处理 POST 请求。
我尝试过 flashvars,但没有效果(尽管不完全确定 HTML 格式是否发送到 HTML 内的嵌入 SWF - 就像我说的,如果是的话,找到了 100 个示例)
HTML:
<param name="flashvars" value="test='default text'" />
MXML:
if (FlexGlobals.topLevelApplication.parameters.hasOwnProperty("username"))
{
Alert.show(FlexGlobals.topLevelApplication.parameters.username);
}
//Alert.show(LoaderInfo(this.root.loaderInfo).parameters.username);//also fails
大多数情况下都很简单我曾经使用过其他语言,但对 FLEX 没有什么好感。我显然缺少一些基本的东西。
From an HTML form, I wish to launch my existing working flex application passing in parameters E.G, login details.
Lets say I have a simple HTML page with no FLASH in it at all.
<h1>Test sending parameters</h1>
<form name="login" action="http://example.com/myflexApp/index.html"
target="_new" method="POST">
username: <input type="text" name="username" />
password: <input type="text" name="password" />
<input type="submit" value="Submit" />
</form>
This will open up my application for the first time in a new browser window
My index.mxml which is compiled to create index.html looks like this (simplified):
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
...
creationComplete="init(event)" xmlns:omp="omp.*">
<fx:Style source="defaults.css"/>
<fx:Script>
<![CDATA[
import ...
protected function init(event:FlexEvent):void
{
if (params[username] && params[password])//psuedo code
{
Alert.show(params[username],params[password]);//debugging
//login(params[username],params[password]);//psuedo code to log in automatically
}else{
//existing code to show login form which works
}
}
]]>
</fx:Script>
<mx:ViewStack id="vs" width="100%" height="100%" ...>
</mx:ViewStack>
</s:Application>
So what should the html code look like and what is the corresponding actionscript code that goes into the init() function?
Or, at least what should I be googling for?
Note: Obviously it is not acceptable to have the parameters and values showing in the browser's URL address. Otherwise this would be easy.
Also note, the application is not embedded in the original HTML page, although 99.9% of search results I found on this topic gives an example of what to do if it was.
Ideally the original request would be a POST request but apparently flex can't handle post requests.
I've tried flashvars to no avail (although not entirely sure of the HTML format if it's not sending to an embedded SWF inside the HTML - and like I said, found 100's of examples if it was)
HTML:
<param name="flashvars" value="test='default text'" />
MXML:
if (FlexGlobals.topLevelApplication.parameters.hasOwnProperty("username"))
{
Alert.show(FlexGlobals.topLevelApplication.parameters.username);
}
//Alert.show(LoaderInfo(this.root.loaderInfo).parameters.username);//also fails
So simple in most other languages I've worked with but having no luck with FLEX. I'm obviously missing something basic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谷歌搜索我发现了以下示例:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html
有一个代码片段应该跟踪所有传递的“flashVars”,
也许可以先尝试这个,你会看到你传递给你的弹性应用程序的参数。
你的 html 应该看起来像这样:
你必须添加 flashvars 两次,而不是一次。我真的不知道 flashvars 是否像您在示例中添加的
'
或
一样。另一件事:您不想将用户的密码以明文形式发布 - 使用某种 md5 哈希对其进行编码。
googling this i found the following example:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf626ae-7feb.html
there's is a code snippet that should trace all passed `flashVars``
maybe try this first and you'll see what parameters you're passing to your flex-app.
your html should look something like this:
you have to add the flashvars twice, not just once. and i don't really know if flashvars like the
'
or the<space>
you added in your example.one other thing: you don't want to POST your user's password as plaintext - use somekind of md5-hash to encode it.