Learn a little flash (40) every day to make things

Source: Internet
Author: User
Tags addchild

Add another mouse trigger event based on the original one, that is, the response to the click event. When we click on each image, we can determine the URL of each connected image. The Code is as follows:

Package {import flash. display. movieclip;

Import flash. display. Sprite;

Import flash. display. loader;

Import flash. Events .*;

Import flash. utils. *; // The execution Interval

Import flash.net .*;

Import flash. system. system;

Public class picture extends movieclip {

Private var tempmc: Mc;

Private var movetime: timer;

Private var picarray: array; // loads multiple video clips

Private var imgarray: array; // load multiple loader objects

Private var myurl: array; // load the URL in XML

Private var list: array; private var myxml: XML;

Private var mylist: xmllist;

Private var ld: loader;

Private VaR _ Loader: urlloader;

Public Function picture (){

System. usecodepage = true;

Picarray = new array ();

Imgarray = new array ();

Myurl = new array ();

List = new array ();

Myxml = New XML ();

Myxml. ignorewhite = true;

_ Loader = new urlloader ();

_ Loader. Load (New URLRequest ("menu. xml "));

_ Loader. addeventlistener (event. Complete, loading );

For (var I: Int = 0; I <7; I ++ ){

Tempmc = new MC ();

Tempmc. addeventlistener (mouseevent. mouse_over, stoping); // generates a mouse event

Tempmc. addeventlistener (mouseevent. mouse_out, starting); // generates a mouse event

Tempmc. addeventlistener (mouseevent. Click, clicking); // generates a click event

Tempmc. Name = "tempmc" + I;

Picarray. Push (tempmc );

Addchild (picarray [I]);

Picarray [I]. x = I * picarray [I]. width;

}

Movetime = new timer (80 );

Movetime. addeventlistener (timerevent. Timer, picmove); movetime. Start ();}

Private function picmove (Event: timerevent): void {

For (var t: Int = 0; t <7; t ++ ){

Picarray [T]. X-= 5; If (picarray [T]. x <-88 ){

Picarray [T]. x = 6*88 ;}}}

 

Private function loading (EVT: Event): void {

Myxml = XML (_ loader. data );

Mylist = myxml. Children ();

Trace (mylist );

For (var j: Int = 0; j <mylist. Length (); j ++ ){

List [J] = mylist. Attribute ("url") [J];

Myurl [J] = mylist. Attribute ("myurl") [J];

Trace (list [J]);

LD = new loader (); // used to load images

LD. Name = "LD" + J; // This is an important position. Change the name of each loader object.

Imgarray. Push (LD); // manage multiple loader objects

Imgarray [J]. Load (New URLRequest (list [J]);

Picarray [J]. addchild (imgarray [J]);

}

} Private function stoping (E: mouseevent): void {movetime. Stop (); // stop the image motion

} Private function starting (E: mouseevent): void {movetime. Start (); // Let the image start Motion

} Private function clicking (E: mouseevent): void {

For (var k: Int = 0; k <7; k ++ ){

VaR STR: String = "LD" + k; // when the name of the image you click matches the URL of the corresponding image, a response is returned.

If (e.tar get. Name = Str ){

NavigatetoURL (New URLRequest (myurl [k]);

} Else {trace ("cuowu ");

}

} Trace(e.tar get. Name );

}}}

XML File Settings:

<? XML version = "1.0" encoding = "gb2312"?>

<Item> <menuname url = "Photo/1.jpg" myurl =" http://www.baidu.com "/>

<Menuname url = "Photo/2.jpg" myurl =" http://www.hao123.com "/>

<Menuname url = "Photo/3.jpg" myurl =" http://www.sina.com.cn/"/>

<Menuname url = "Photo/4.jpg" myurl =" http://www.163.com "/>

<Menuname url = "Photo/5.jpg" myurl =" http://www.yahoo.com "/>

<Menuname url = "Photo/6.jpg" myurl =" http://www.nba.com "/>

<Menuname url = "Photo/7.jpg" myurl =" http://www.pchome.com "/>

</Item>

 

Set the first frame:

VaR P: Picture = new picture (); addchild (P );

Summary: this complete drive lamp uses a lot of Integrated flash syntaxes and is good as a exercise file. Well, write it here ..

The lawn lights are basically finished.

 

 

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.