相关文章:与浏览器脚本的交互的方法(一)
3LoadVars
使用LoadVars可以更好地控制数据的传递与接收.
例子:
场景上有一个组件Textarea(textarea1)和三个组件Button(btu1,btu2,btu3)
Flash的AS
var lv = new LoadVars();
var ll = new LoadVars();
lv.str = "Flash to IIS";
function handle_btu1() {
lv.id = this.label;
lv.send("http://localhost/fmx/pass2.asp", "_blank", "POST");
//无论是“POST”,还是“GET”方式,FLASH都是以“GET”方式发送。
}
function handle_btu2() {
lv.id = this.label;
lv.load("http://localhost/fmx/pass2.asp");
}
function handle_btu3() {
lv.id = this.label;
lv.sendAndLoad("http://localhost/fmx/pass2.asp", ll, "POST");
}
this.btu1.addEventListener("click", mx.utils.Delegate.create(this.btu1, handle_btu1));
this.btu2.addEventListener("click", mx.utils.Delegate.create(this.btu2, handle_btu2));
this.btu3.addEventListener("click", mx.utils.Delegate.create(this.btu3, handle_btu3));
lv.onLoad = function(success) {
_root.textarea1.text = this.rebackdata;
};
ll.onLoad = function(success) {
_root.textarea1.text = _root.textarea1.text+"\n"+this.rebackdata;
};
服务器脚本存放于WEBSERVER根目录下
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<%
restr=Request("str")
reid=Request("id")
Response.Write("rebackdata=Say hello from "+reid+" : "+restr)
%>
4 ExternalInterface
Flash发展到8时,又加入了一个类flash.external.ExternalInterface,它可以在影片中调用容器定义的函数,容器也可以调用影片定义的函数。
例子:
在场景中建一个label,命名为label1,文档保存为test.fla
第一帧代码:
import flash.external.*;
var methodName:String = "goHome";
var instance:Object = this;
var method:Function = goToMacromedia;
var wasSuccessful:Boolean = ExternalInterface.addCallback(methodName, instance, method);
var txtField:TextField = this.createTextField("txtField", this.getNextHighestDepth(), 0, 0, 200, 50);
txtField.border = true;
txtField.text = wasSuccessful.toString();
function goToMacromedia():Boolean {
txtField.text = "http://www.macromedia.com";
getURL("http://www.macromedia.com", "_self");
return true;
}
IE中的代码:
function callExternalInterface() {
b=thisMovie("test").goHome();
if(b){
alert("The box is checked.");
}
}
function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
}
else {
return document[movieName];
}
}
嵌入Flash对象
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="test" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="test.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="swLiveConnect" value="true" />
<embed src="test.swf" quality="high" bgcolor="#ffff00" width="550" height="400" name="test" swLiveConnect="true" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>