动作嵌入一个数组 [英] Actionscript embed an array

查看:223
本文介绍了动作嵌入一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要嵌入一些图片在编译时间,所以我最终只是一个单一的SWF。 他们需要的是一个数组里面,因为我需要通过程序来修改他们,他们可以是图像的100S。不能使用弯曲,因为我要保持动作的整体功能(也就是使文件更小)

I want to embed some images at compilation time so I end up with just a single swf. They need to be inside of an array as I need to modify them programatically and they can be 100s of images. Cant use flex as I want to keep the whole function in actionscript (aka make files smaller)

我发现如何做到这一点的弯曲:

I found how to do it in flex:

...
<mx:Array id="test">
   <mx:Image id="image0" source="@Embed(source='../../../lib/Images033,jpg')" />
   <mx:Image id="image1" source="@Embed(source='../../../lib/Images034,jpg')" /> 
   <mx:Image id="image2" source="@Embed(source='../../../lib/Images035,jpg')" />
   <mx:Image id="image3" source="@Embed(source='../../../lib/Images036,jpg')" />
</mx:Array>
...
addChild(test[1] as something);
...

因此,没有人知道该怎么做上面只是在Actionscript中?

非常感谢。

推荐答案

那么,这种或那种方式,你将需要一个嵌入语句为每个的 的要嵌入的东西,所以你不会真的能够得到解决的。但是,如果你想preFER处理一切都在脚本中,你可以做这样的事情(这是一个AIR应用程序,但在WindowedApplication标签之间的一切都应该在一个普通的醇'Flex应用程序的工作):

Well, one way or another, you're going to need an Embed statement for every thing you want to embed, so you won't really be able to get around that. But if you'd prefer to handle everything in script, you could do something like this (it's an AIR application, but everything between the WindowedApplication tags should work within a plain ol' Flex app):

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="onInitialize()">

    <mx:Script>
    	<![CDATA[

    		import mx.controls.Image;

    		private var images:Array;
    		private const IMAGE_COUNT:uint = 5;

    		[Embed(source='Image0.png')]
    		private var Image0:Class;

    		[Embed(source='Image1.png')]
    		private var Image1:Class;

    		[Embed(source='Image2.png')]
    		private var Image2:Class;

    		[Embed(source='Image3.png')]
    		private var Image3:Class;

    		[Embed(source='Image4.png')]
    		private var Image4:Class;

    		private function onInitialize():void
    		{
    			images = new Array(IMAGE_COUNT);

    			// Populate your array with Class references to embedded imagery
    			for (var i:int = 0; i < IMAGE_COUNT; i++)
    			{
    				images[i] = this["Image" + i];
    			}
    		}

    		override protected function createChildren():void
    		{
    			super.createChildren();

    			// Add your children to the display list
    			for (var i:int = 0; i < IMAGE_COUNT; i++)
    			{
    				var img:Image = new Image();
    				img.source = images[i];

    				addChild(img);
    			}
    		}

    	]]>
    </mx:Script>

</mx:WindowedApplication>

所以基本上你在做什么,并确保您的图像是根据一些数字方案中的所有嵌入在编译时和命名(在这种情况下,只是附加了一个索引),是填补你的数组类引用,再经过实例化和期间在createChildren()相组件的生命周期的将它们添加到显示列表

So essentially what you're doing, after making sure your images are all embedded at compile time and named according to some numeric scheme (in this case, just appended with an index), is filling your array with Class references, then instantiating and adding them to the display list during the createChildren() phase of the component lifecycle.

这里也有一些深奥的东西,怎么回事,所以如果你不太明白一切,随意评论回来,我会密切关注的事情。但这种测试code,也应该pretty的好了你,给你如何解释您的要求为止。

There's some esoteric stuff going on here, so if you don't quite understand everything, feel free to comment back, and I'll keep an eye on things. But this is tested code and should work pretty well for ya, given how you've explained your requirements so far.

这篇关于动作嵌入一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆