将变量传递给 swf 文件
pass variable to swf file
我有一个 Actionscript 2.0 代码(.swf 文件)以连续的方式加载图像。我希望 swf 从 html 代码接收变量并加载图像
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();
要将值传递到 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;
}
}
我有一个 Actionscript 2.0 代码(.swf 文件)以连续的方式加载图像。我希望 swf 从 html 代码接收变量并加载图像
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();
要将值传递到 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;
}
}