My random image as3 code

January 14, 2009 at 6:32 pm Leave a comment

var listLoader:URLLoader = new URLLoader( new URLRequest(“http://mediaweb.aib.ac.uk/fdashow09/Mitchell/filelist.xml”) ); // download from
var picLoader:Loader = new Loader();

listLoader.addEventListener(Event.COMPLETE, gotList);

function gotList(evt:Event):void {
var xmlData:XML = XML(listLoader.data); // type of list to look for
var numImages:Number = xmlData.pix.length();

var stImage:String = xmlData.pix[Math.floor(numImages*Math.random())].toString(); // randomise the images

picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, gotPic);
picLoader.load( new URLRequest(stImage) );

listLoader.removeEventListener(Event.COMPLETE, gotList);
}

function gotPic(evt:Event):void {
var thisBmp:Bitmap = Bitmap(evt.target.content);
thisBmp.x = 0; // change the x place of the image
thisBmp.y = 0; // change the y place of the image
var thisWidth:Number = thisBmp.width;
var thisHeight:Number = thisBmp.height;

var pHeight:Number = 400; // change the hight of the images
var pWidth:Number = 600; // change the width of the images

thisBmp.scaleX = pWidth/thisWidth; // appily pWidth to scale
thisBmp.scaleY = pHeight/thisHeight; //appily pHeight to scale
addChild(thisBmp);

picLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, gotPic);
thisBmp.addEventListener(Event.ENTER_FRAME, anything);
}
function anything(E:Event):void
{
E.target.alpha=Math.random();
}

Advertisements

Entry filed under: Advanced Web Design, FDA interactive Media Yr2.

More advanced web design posting and evaluation My rss circle feed code

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


January 2009
M T W T F S S
« Dec   Feb »
 1234
567891011
12131415161718
19202122232425
262728293031  

Categories

Recent Posts


%d bloggers like this: