ActionScript 3.0: load an image programatically

感情迁移 提交于 2019-12-11 16:50:07

问题


I'm developing an Blackberry Playbock app with ActionScript 3.0. I'm very very new with this.

I have the following project structure (I'm using Adobe Flash Builder "Burrito"):

project | src | assets | images

On image folder I have several PNGs images that I want to load programmatically.

How can I do that?

And

What GUI component I must use to show an image?


回答1:


This example loads one image and uses buttons to change it:

// create a Loader object to hold things that you will load
var myLoader:Loader = new Loader();

// position the Loader
myLoader.x = 250;
myLoader.y = 0;

// put something into the Loader 
myLoader.load(new URLRequest("tree.jpg"));

// make the Loader visible
addChild(myLoader);

// button listeners
top_btn.addEventListener(MouseEvent.CLICK, loadPhoto);
last_btn.addEventListener(MouseEvent.CLICK, unloadAny);

// button functions
function loadPhoto(e:MouseEvent):void {
    myLoader.load(new URLRequest("sailboat.jpg"));
    addChild(myLoader);
}
// this function empties the Loader object 
function unloadAny(e:MouseEvent):void {
    removeChild(myLoader);
}



回答2:


Use the Loader class.




回答3:


if u want to show multiple image using for loop then follow this code:

var IMAGE_URL:String = new String("image/");

for(var i=1;i<=13;i++){
    addChild(imageLoder(i,i*25));
}

 private function imageLoder(ranvalue:int,cor:int):Loader{
      var ldr:Loader = new Loader();
      ldr.load(new URLRequest(IMAGE_URL+ranvalue+".jpg"));
      var xcord=5;
      var ycord=5;
      ldr.x = cor;
      ldr.y = ycord+20;
      return ldr;
  }


来源:https://stackoverflow.com/questions/5222352/actionscript-3-0-load-an-image-programatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!