好的,我正在制作闪存游戏。在这个游戏中你需要找到2张相同的牌并发现它们。这里有36张牌(6x6)。
当它产生时,我有2张不同的卡片图像。 1.png我需要使用30次和2.png我需要使用6次。 示例(星星应该是2.png):
有可能吗?
这是我的Card.as Movie Clip
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Card extends MovieClip
{
public var _type:*;
public function Card()
{
this.buttonMode = true;
this.addEventListener(MouseEvent.CLICK, onClick);
}
private function onClick(event:MouseEvent):void
{
if(this.currentFrame == 1)
{
this.play();
}
}
public function setType(type:*):void
{
_type = type;
loader_mc.addChild(_type);
}
}
}
非常感谢。
答案 0 :(得分:0)
使用Loader或URLLoader加载文件后,您需要将加载的内容转换为可重用的对象。
private var starsVec:Vector.<Bitmap > = new Vector.<Bitmap > ;
private var starBitmapData:BitmapData;
public function shiiiit()
{
var loader:Loader = new Loader ;
var url:URLRequest = new URLRequest("plik.png");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoaded);
loader.load(url);
}
private function onLoaded(e:Event):void
{
//saves loaded graphic file into BitmapData object
starBitmapData = new BitmapData(e.target.content.width,e.target.content.height,true,0);
starBitmapData.draw(e.target.content);
createTable();
}
private function createTable():void
{
for (var i:uint=0; i<6; i++)
{
//now use BitmapData object to create new Bitmap object and add it to stage
starsVec.push(new Bitmap(starBitmapData));
var starsVecTopElem:Bitmap = starsVec[starsVec.length - 1];
addChild(starsVecTopElem);
}
}