Flex中取得URL的参数!

类别:编程语言 点击:0 评论:0 推荐:

其实根本就是直接拿进来用,被骗了吧,呵呵!

?login=genedna

login作为mxml中的一个参数直接使用,如下:

<mx:Label text="{login}"></mx:Label>

补充修改:2005-1-26

今天这样来写程序发现竟然不能认login这个参数,仔细的翻阅了Macromedia的论坛和文档,终于搜索到官方的版本,内容如下:

Passing request data to Flex applications
You can pass variables to Flex applications using a query string parameter or defining flashVars properties. When you use query string parameters, Flex converts them to flashVars variables and passes them into the application.

Flex does not recompile the application if the request variables have changed. As a result, if you dynamically set the values of the flashVars or query string parameters, you do not force a recompilation.

Parameters must be URL encoded. The format of the string is a set of name-value pairs separated by an ampersand (&). You can escape special and/or nonprintable characters with a percent sign (%) followed by a two-digit hexadecimal value. You can represent a single blank space using the plus sign (+).

The encoding for flashVars and query string parameters is the same as the page containing it. Internet Explorer provides UTF-16-compliant strings on the Windows platform. Netscape sends a UTF-8-encoded string to Flash Player.

Most browsers support a flashVars String or query string up to 64KB (65535 bytes) in length. They can include any number of name-value pairs.

To use the values of the passed Strings in a Flex application, you must declare them as variables. If you pass a query string parameter or flashVars property to Flex but do not declare it as a variable in the MXML file, Flex ignores the value.

To use flashvars or query string parameters inside your MXML file, declare the parameter name at the top of a script block. You can then access it as you would any variable inside the Flex application. You can bind its value to a display control or modify the value and return it to another function.

The following example defines the name and hometown variables and binds them to the text of TextInput controls:

<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" >
   <mx:Script><![CDATA[
      var name: String = "None"; // Set default value if none is passed.
      var hometown: String = "None"; // Set default value if none is passed.
   ]]></mx:Script>
   <mx:TextInput text="Name: {name}" />
   <mx:TextInput text="Hometown: {hometown}" />
</mx:Application>

When a user requests this application with name and hometown parameters defined, Flex displays them in the TextInput controls. The following URL passes the name Reiner and the hometown Berlin to the Flex application:

http://localhost:8100/flex/myApp.mxml?name=Reiner&hometown=Berlin

要提前声明两个空的字符串保存变量才可以,我以前明明记得直接用就行。晕倒!

本文地址:http://com.8s8s.com/it/it23370.htm