我有一个Action Script 2.0代码(.swf flie)以连续的方式加载图像。我想从html代码加载swf接收变量并加载图像
var current_loader:Number = 1;
var current_img:Number = 0;
this.createEmptyMovieClip('img_01', 999);
this.createEmptyMovieClip('img_02', 998);
img_01._x = img_01._y = img_02._x = img_02._y = 20;
var loader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
listener.onLoadStart = function(target_mc:MovieClip){ }
listener.onLoadProgress = function(target_mc:MovieClip,numBytesLoaded:Number, numBytesTotal:Number) { }
listener.onLoadComplete = function(target_mc:MovieClip) {
if(target_mc._name == 'img_01'){
img_02._visible = false;
} else {
img_01._visible = false;
}
}
var interval:Number = setInterval(load_image, 1000);
function load_image() {
loader.addListener(listener);
loader.loadClip("http//google.flower.php", _root['img_0'+current_loader]);
current_loader = current_loader == 1 ? 2 : 1;
current_img = current_img == images.length - 1 ? 0 : current_img + 1;
}
load_image();
答案 0 :(得分:1)
要将值传递给swf文件,您可以使用FlashVars
,如下所示:
在您的对象代码中:
<object type="application/x-shockwave-flash" data="my_swf.swf" width="400" height="400">
<param name="movie" value="my_swf.swf" />
<param name="flashvars" value="var_passed_from_html=example" />
<!-- other params -->
</object>
嵌入代码(如果使用):
<embed src="my_swf.swf" flashvars="var_passed_from_html=example" <!-- other params --> />
对于ActionScript 2,在swf中,您可以像任何其他变量一样直接获取该值:
trace(var_passed_from_html); // gives : example
有关详细信息,请查看如何pass variables to SWFs。
希望可以提供帮助。
修改:
示例:
<object type="application/x-shockwave-flash" data="my_swf.swf" width="400" height="400">
<param name="movie" value="my_swf.swf" />
<param name="flashvars" value="img_url=http://www.example.com" />
<!-- other params -->
</object>
AS2代码:
var image_url:String = 'empty'; // set a default value
if(img_url){ // if we have received an image url from HTML
image_url = img_url;
}
function load_image() {
if(image_url != 'empty'){ // if image_url is not "empty", load it
loader.addListener(listener);
loader.loadClip(image_url, _root['img_0'+current_loader]);
current_loader = current_loader == 1 ? 2 : 1;
current_img = current_img == images.length - 1 ? 0 : current_img + 1;
}
}