[Flash] dynamic loading of multiple images

Source: Internet
Author: User
From: http://www.healdream.com/blog/article.asp? Id = 150

View results: Online Flash Animation playback

Updated the source file, hoping to help you :)

I thought that there were many tutorials like this on the Internet, but the results were not ideal, but I also saw some useful articles.

We know that it is relatively simple to load the movi1_loader into a single graph. But if it is a multi-graph, how can we establish a listener? After loading an image, how does one load the next image? How to combine with XML?

Let's start with the listening problem one by one. n objects cannot be created for so many images, and then they can be listened to separately, which is too inefficient. Therefore, only one listener can be created, the remaining task is how to load multiple graphs.

Basic Ideas:

Assign id 1 first, and then determine the size of the id and the total number of images to determine whether to load the next image, just like this: program code myObj. onLoadComplete = function (){
If (id <= nums) {// after an image is loaded, determine the value of id and nums. if it is smaller than nums, Continue loading.
Id ++;
Loadpic (id );
}
};

Then execute the program code myCL. loadClip (imgurl, loadpic_mc) in the loadpic (id) function );

You can continue loading.

Finally, the problem of integration with XML is actually quite simple. When the external xml is loaded, execute the corresponding function, just like this: the program code myXML. onLoad = function (suc ){
If (suc ){
LoadStart (); // execute the loadStart function after loading.
}
};

The basic idea is to paste the source code: program code var id = 1;
Var myXML: XML = new XML ();
MyXML. ignoreWhite = true;
MyXML. load ("list. xml"); // load xml
MyXML. onLoad = function (suc ){
If (suc ){
LoadStart (); // execute the loadStart function after loading.
}
};
Var myObj: Object = new Object ();
MyObj. onLoadComplete = function (){
If (id <= nums) {// after an image is loaded, determine the value of id and nums. if it is smaller than nums, Continue loading.
Id ++;
Loadpic (id );
}
};
MyObj. onLoadInit = function (tar) {// after loading, set the image size
Tar. _ width = 85;
Tar. _ height = 53;
Tid = id-1;
// Set the loading and gray backgrounds to invisible and add events to the buttons
// Here is a small trick: Assign tid to _ btn. pid to facilitate future calls.
_ Root ["loader" + tid + "_ mc"]. loading_mc. _ visible = false;
_ Root ["loader" + tid + "_ mc"]. bg1_mc. _ visible = false;
_ Root ["loader" + tid + "_ mc"]. _ btn. pid = tid;
_ Root ["loader" + tid + "_ mc"]. _ btn. onRelease = function (){
Ttid = this. pid;
Url = myList [ttid]. childNodes [0]; // obtain the url corresponding to the xml file
GetURL (url );
};
};
Var myCL: movi1_loader = new movi1_loader ();
Function loadStart (){
MyList = myXML. firstChild. childNodes;
Nums = myList. length; // obtain the number of images.
For (var I = 1; I <= nums; I ++) {// copy the mc in the library, place it on the stage, and assign their coordinates.
_ Root. attachMovie ("bg_loader", "loader" + I + "_ mc", 100 + I );
_ Root ["loader" + I + "_ mc"]. _ x = (I % 5 = 0 )? 450: (10 * (I % 5) + 100 * (I % 5-1 ));
Ty = I % 5 = 0? (Math. floor (I/5-1) * 80): (Math. floor (I/5) * 80 );
_ Root ["loader" + I + "_ mc"]. _ y = 10 + ty
}
MyCL. addListener (myObj); // sets the listener
MyCL. loadClip ("imgs/small01.jpg", _ root. loader=mc.loadpic_mc); // load the first image
}
Function loadpic (id ){
// Obtain the corresponding image address in the xml file
Imgurl = myList [id-1]. attributes. path;
MyCL. loadClip (imgurl, _ root ["loader" + id + "_ mc"]. loadpic_mc );
}

View results

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.