Learn a little about flash (52) stage every day

Source: Internet
Author: User

I. Comparison

Reference a cookbook statement:

Stage is the root node at the visualization Object List level. Each movie has a stage object that contains
Object. In fact, stage is a container. You can reference the stage attribute to access any visualization object.

 

Reference help document:

The stage class represents the main drawing area. The stage indicates the entire area of the Flash content.

Stage objects cannot be accessed globally. Instead, you must use the displayobject instance'sstageAttribute.

The stage class has multiple ancestor classes: displayobjectcontainer, interactiveobject, displayobject, and eventdispatcher. attributes and methods are inherited from these classes. Many of the attributes and methods inherited from these do not apply to stage objects, or require security checks when calling stage classes. Attributes and methods for security check are recorded as part of the stage class.

 

Make a small experiment:

Problem: addeventlistener (event. enter_frame, run) and

Stage. addeventlistener (event. enter_frame, run2); what is the difference?

Package <br/> {<br/> Import flash. display. movieclip; <br/> Import flash. events. *; <br/> public class example2 extends movieclip <br/> {<br/> Public Function example2 () <br/>{< br/> addeventlistener (event. enter_frame, run); <br/> stage. addeventlistener (event. enter_frame, run2); <br/>}< br/> private function run (Event: Event): void <br/>{< br/> trace ("event is: "events event.tar get); <br/> trace (" event is: "+ event. currenttarget); <br/> trace ("event is:" + event. type); <br/>}< br/> private function run2 (Event: Event): void <br/>{< br/> trace ("event2 is: "events event.tar get); <br/> trace (" event is: "+ event. currenttarget); <br/> trace ("event2 is:" + event. type); <br/>}< br/>}

Output result:

 

Event is: [object example2]
Event is: [object example2]
Event is: enterframe

Event2 is: [object stage]
Event2 is: [object stage]
Event2 is: enterframe

Although it cannot be explained for the time being, there is a small difference between stage and no stage listening in data output. One is a listener stage object, that is, a stage listening, and the other is a class listening.

 

 

Let's look at the stage attributes of the official displayobject class:

    Stage: Stage

[Read-Only] displays the stage of an object.
Displayobject

 

The stage attribute of the displayobject class.

Displays the stage of an object. Flash applications only have one stage object. For example, you can create multiple display objects and load them to the display list.stageAttribute refers to the same stage object (even if the Display object belongs to the loaded SWF file ).

If the Display object is not added to the display liststageThe property is setnull

 

Ii. Problems Caused by stage

 

I have encountered such a problem that I wrote in the main document class and other tank classes in the tank class

Stage. addeventlistenr ();

The keyboard operation defined in the tank class is totally invalid.

Tank Class:

For example, public function tank ()

      {

Stage. addeventlistenr ();

      }

// Keyboard listener

 

Main class:

Public Function main (): void

{

VaR my: tank = new tank ();

Addchild (my );

}

However, this is ineffective. I guess the stage can be understood as a stage. Because there is only one stage for the performance, the stage fails in the tank class.

To solve this problem, I made such a small move:

 

Public Function tank (stage: Object)

      {

Stage. addeventlistenr ();

      }

In this way, the class created in the main class can implement keyboard monitoring.

In fact, when a SwF is loaded from the external, the stage will also encounter this problem. As for the specific good method, I have not found it yet. If someone knows it, it can solve the problem better, you can leave a message to me.

 

 

 

 

 

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.