0

フォルダからランダムな画像を選び、それをセージに表示するには、何を使用すればよいですか?1.Math.randomthingy-乱数をロールする2.XMLファイル-フラッシュファイルに組み込む方法がわからない3.写真の入ったフォルダー?

4

2 に答える 2

0

1.画像を配置するには、次のようにflaします。

ここに画像の説明を入力してください

2.以下を試してください。以下のコードは単なるスケルトンです。もっと拡張してみてください。

import flash.display.Bitmap;
import flash.events.Event;
import flash.net.URLRequest;
import flash.display.Loader;

var imgRequest:URLRequest;
var randCount:int = 6*Math.random();
function loadImage():void
{
    for(var i:int = 0; i<randCount; i++)
    {
        var imgLoader:Loader = new Loader();
        imgRequest = new URLRequest();
        imgRequest.url = "img/img" + int(6*Math.random()) +".jpg";
        trace(imgRequest.url);
        imgLoader.load(imgRequest);
        imgLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, unloadedImg);
        imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadedImg);
    }
}

function onLoadedImg(e:Event):void
{
    e.currentTarget.removeEventListener(Event.COMPLETE, onLoadedImg);

    var bmp:Bitmap = e.currentTarget.content;

    bmp.x = Math.random() * stage.stageWidth;
    bmp.y = Math.random() * stage.stageHeight;
    bmp.width = 200;
    bmp.height = 200;
    this.addChild(bmp);
}

function unloadedImg(e:IOErrorEvent):void
{
    e.currentTarget.removeEventListener(IOErrorEvent.IO_ERROR, unloadedImg);
    trace("load Failed:" + e);
}

loadImage();
于 2013-02-12T10:46:17.550 に答える
0

画像の配列を作成してから、数学をランダムにする必要があります。

var selected:Array=[];//new array

while (selected.length<4) {

    //myArray is the array with your pictures.
    var si:int=Math.floor(Math.random()*_myArray.length);

    if (selected.indexOf(si)==-1) selected.push(si);
}

trace(_myArray[selected[0]]); // first selected flag
trace(_myArray[selected[3]]); // fourth selected flag
于 2013-05-29T11:34:40.683 に答える