使用AS3代码导出更多.swf文件

时间:2013-07-26 09:35:35

标签: actionscript-3 export flash flash-cs5

我的Flash Professional中有一些动画,我需要这个动画200多次,上面有不同的文字。在for循环中,文本已经是动态的。我想要的是创建一个循环,用不同的文本创建.swf。所以我只执行一次,它会自动创建超过200个.swf文件。这可能吗?

1 个答案:

答案 0 :(得分:0)

您可以尝试只使用一个swf文件,而不是使用200个swf文件,并使用Flashvar来定义要显示的文本。 以下是如何执行此操作的快速示例,以及如何使用它。

在Flash代码中,你会有类似的东西:

// var myTextField:TextField; // in this sample, I want to set the content of myTextField 
// here, I am using an Object as an associative Array. Thus, I can do textTable[''] to obtain 'text sample 1'
var textTable:Object = {
  label1 : "text sample 1",
  label2 : "foo bar",
  showError : "some error occured",
  pizza : "I love pizza"
  // [...]
}

// I'm fetching the flashvars in params, and then specifically the content of the labelKey Flashvar.
var params:Object = LoaderInfo(this.root.loaderInfo).parameters;
var key:String = params.labelKey;

// I'm getting the text that correspond to the given key, and set myTextField with it.
var label:String = textTable[key];
if (label != null) {
  myTextField.text = label;
}

如果你在HTML中加载swf,你会在HTML中有类似的东西:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" id="main">
  <param name="movie" value="main.swf" />
  <param name="FlashVars" value="labelKey=label2" /><!-- Flashvar : we set labelKey to 'label2' - the swf will show "foo bar" -->
  <embed src="main.swf" width="550" height="400" autostart="false" quality="high" bgcolor="#ffffff" FlashVars="labelKey=label2" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

如果不这样做,并且只使用URL,它将如下所示:

http://my.domain.com/main.swf?labelKey=label1
or
http://my.domain.com/main.swf?labelKey=showError
or
http://my.domain.com/main.swf?labelKey=pizza
相关问题