Learn a little flash notes every day (28) as3.0 custom class notes (2)

Source: Internet
Author: User
Tags addchild

After the last problem, I am very grateful to the netizen for giving me the original file "emergency". Here I am very grateful to him for his passion for Flash technology.

Some of the problems have been solved today. I have changed some of his classes. In the future, we can try to call the external loading XML method to find out our answer. I have a new view on listening for class write events. In as3.0

Read this sentence:

This. dispatchevent (new event (event. Complete ));

Getmyxml. As File

Package {
Import flash. display. Sprite;
Import flash.net. urlloader;
Import flash.net. URLRequest;
Import flash.net. urlloader;
Import flash. Events .*;
Import flash. Text. textfield;
Public class getmyxml extends sprite {
Public var myxml: XML;
Public var picarray: array = new array ();
Public var URL: string;
Public Function getmyxml (myurl: string ){
Myxml = New XML ();
Url = myurl;
VaR myurlrequest: URLRequest = new URLRequest (URL );
VaR myloader: urlloader = new urlloader (myurlrequest );
Myloader. addeventlistener (event. Complete, OK );

}

Function OK (E: Event): void {
Myxmlbeanxml(e.tar get. data );
VaR N: Int = myxml. Elements ("*"). Length ();
VaR STR: string;
For (var I: Int = 0; I <n; I ++ ){
STR = (myxml. Elements ("*") [I]). tostring ();
Picarray. Push (STR );
// Trace (picarray [I]);

}

// Trace (Me. mypic (picarray ));

// Addchild (me );
// Addchild (_ Str );
This. dispatchevent (new event (event. Complete); // This place is of special interest today. Add a listening event to the class you write.
}


}


}

Note: Reference official documents

Schedule events to the event stream. The event target is to call it.dispatchEvent()The eventdispatcher object of the method.

Schedule events to the event stream.

Readmyxml.

Package {
Import flash. display. Sprite;

Import flash. Events .*;
Import flash. Text. textfield;
Public class readmyxml extends sprite {

Public var myarray: array = new array ();
Public Function readmyxml (){

}
Public Function mypicture (list: array): Array {
Myarray = List;
Return myarray;

 

}
}

}

Write at the first frame:

VaR okxml: getmyxml = new getmyxml ("pic. xml ");
Addchild (okxml );
Okxml. addeventlistener (event. Complete, good );
Function good (E: Event): void {
Trace ("good ");
 
VaR _ STR: textfield = new textfield ();
VaR me: readmyxml = new readmyxml ();
_ Str. Text = me. mypicture (okxml. picarray). tostring ();
Addchild (_ Str );
Addchild (me );
 
 
}

 

PIC. xml file

<? XML version = "1.0" encoding = "UTF-8"?>
<Map>
<JPG> a0.jpg </jpg>
<JPG> a1.jpg </jpg>
<JPG> a2.jpg </jpg>
<JPG> a3.jpg </jpg>
<JPG> a4.jpg </jpg>
<JPG> a5.jpg </jpg>
<JPG> a6.jpg </jpg>
</Map>

Before that, I often tried to add getmyxml to the document class and found that there was always an error.

It seems that there are some problems, but it will not happen if you put the source file and the as file in the same directory, and you can also call your own method.

Okay. Record some good articles next time.

 

 

 

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.