写了一个例子。
先说flash as3吧,可以用root.loaderInfo.parameters
AS3类 GSPManager.as 代码:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
public class GSPManager extends Sprite
{
public function GSPManager()
{
this .addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
}
private function addedToStageHandler(e:Event): void
{
this .removeEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
init();
}
private function init(): void
{
var out_txt:TextField = new TextField();
// 边框
out_txt.border = true ;
// 边框颜色
out_txt.borderColor = 0x80FF3300 ;
// 大小
out_txt.width = 100 ;
out_txt.height = 20 ;
// 位置
out_txt.x = (stage.stageWidth - out_txt.width) / 2;
out_txt.y = (stage.stageHeight - out_txt.height) / 2;
// 添加到舞台
addChild(out_txt);
// 获得参数对象
var param:Object = root.loaderInfo.parameters;
if (param[ " name " ] != null )
{
out_txt.text = param[ " name " ] + param[ " num " ];
trace( " value: " + param[ " name " ]);
// 判断
}
else
{
out_txt.text = " null " ;
trace( " value:null " );
}
}
}
}
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
public class GSPManager extends Sprite
{
public function GSPManager()
{
this .addEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
}
private function addedToStageHandler(e:Event): void
{
this .removeEventListener(Event.ADDED_TO_STAGE,addedToStageHandler);
init();
}
private function init(): void
{
var out_txt:TextField = new TextField();
// 边框
out_txt.border = true ;
// 边框颜色
out_txt.borderColor = 0x80FF3300 ;
// 大小
out_txt.width = 100 ;
out_txt.height = 20 ;
// 位置
out_txt.x = (stage.stageWidth - out_txt.width) / 2;
out_txt.y = (stage.stageHeight - out_txt.height) / 2;
// 添加到舞台
addChild(out_txt);
// 获得参数对象
var param:Object = root.loaderInfo.parameters;
if (param[ " name " ] != null )
{
out_txt.text = param[ " name " ] + param[ " num " ];
trace( " value: " + param[ " name " ]);
// 判断
}
else
{
out_txt.text = " null " ;
trace( " value:null " );
}
}
}
}
GetSwfParam.fla 绑定的文档类为GSPManager.as ,在文档类绑定框里写GSPManager这个就可以了
之后编译出来的GetSwfParam.swf 就可以添加到页面了
Java web页面代码:
<%
@ page language
=
"
java
"
import
=
"
java.util.*
"
contentType
=
"
text/html;charset=GBK
"
%>
<! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.01 Transitional//EN " >
< html >
< head >
< / head>
< body >
< object id = " g " classid = " clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 " codebase = " http://download.macromedia.com/pub/shockwave/_cabs/flash/swflash.cab#version=6,0,29,0 " width = " 300 " height = " 200 " >
< param name = " movie " value = " GetSwfParam.swf?name=sange&num=66 " / >
< param name = " quality " value = " high " / >
< param name = " allowScriptAccess " value = " sameDomain " / >
< param name = " scale " value = " exactfit " / >
< embed name = " g " src = " GetSwfParam.swf " quality = " high " scale = " exactfit " align = " middle " play = " true " loop = " false " pluginspage = " http://www.macromedia.com/go/getflashplayer " type = " application/x-shockwave-flash " width = " 300 " height = " 200 " >< / embed>
< / object>
< / body>
< / html>
<! DOCTYPE HTML PUBLIC " -//W3C//DTD HTML 4.01 Transitional//EN " >
< html >
< head >
< / head>
< body >
< object id = " g " classid = " clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 " codebase = " http://download.macromedia.com/pub/shockwave/_cabs/flash/swflash.cab#version=6,0,29,0 " width = " 300 " height = " 200 " >
< param name = " movie " value = " GetSwfParam.swf?name=sange&num=66 " / >
< param name = " quality " value = " high " / >
< param name = " allowScriptAccess " value = " sameDomain " / >
< param name = " scale " value = " exactfit " / >
< embed name = " g " src = " GetSwfParam.swf " quality = " high " scale = " exactfit " align = " middle " play = " true " loop = " false " pluginspage = " http://www.macromedia.com/go/getflashplayer " type = " application/x-shockwave-flash " width = " 300 " height = " 200 " >< / embed>
< / object>
< / body>
< / html>
这里要说的是swf后有很多参数就用&符号 , 比如GetSwfParam.swf?name=sange&num=66&id=1
现在说Flex了,因为让同事也做了这样的东西,但他只会Flex,他没弄出来,所以我试下,发现用root没反映,但我很肯定Flex应该也可以弄出来,发现跟flash as3确实不同,不能用root,因为Flex中没有root这个概念。问了群里的人,收获大了,原来就Application,哈哈,不就是根节点么,也就相当于root,就是名称不一样。
Flex就用Application.application.parameters
GetSwfParam.mxml 代码:
<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
< mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml " backgroundColor = " #ffffff " layout = " absolute " creationComplete = " init() " >
< mx:Script >
<! [CDATA[
private function init(): void
{
// 获得参数对象
var param:Object = Application.application.parameters;
if (param[ " name " ] != null )
{
mytxt.text = param[ " name " ];
}
else
{
mytxt.text = " null " ;
}
}
]] >
< / mx:Script>
< mx:TextInput id = " mytxt " x = " 60 " y = " 47 "/ >
< / mx:Application>
< mx:Application xmlns:mx = " http://www.adobe.com/2006/mxml " backgroundColor = " #ffffff " layout = " absolute " creationComplete = " init() " >
< mx:Script >
<! [CDATA[
private function init(): void
{
// 获得参数对象
var param:Object = Application.application.parameters;
if (param[ " name " ] != null )
{
mytxt.text = param[ " name " ];
}
else
{
mytxt.text = " null " ;
}
}
]] >
< / mx:Script>
< mx:TextInput id = " mytxt " x = " 60 " y = " 47 "/ >
< / mx:Application>
把编译好的swf添加到页面就可以了。同上,Java web页面代码不变。