<< Chapter < Page Chapter >> Page >

Straightforward code

The code in Listing 3 is fairly straightforward. You should be able to understand it if you analyze it using the ActionScript documentation.

The Event.COMPLETE event handler

The main thing that I want to emphasize from Listing 3 is the registration of the Event.COMPLETE event handler. Note that this event handler is registered on the contentLoaderInfo property of the Loader object and not on the Loader object itself. The documentation has this to say about this property:

"Returns a LoaderInfo object corresponding to the object being loaded. LoaderInfo objects are shared between the Loader objectand the loaded content object. The LoaderInfo object supplies loading progress information and statistics about the loaded file.

Events related to the load are dispatched by the LoaderInfo object referenced by the contentLoaderInfo property of the Loaderobject. The contentLoaderInfo property is set to a valid LoaderInfo object, even before the content is loaded, so that you can add event listeners to the objectprior to the load."

The Event.COMPLETE event

The documentation has this to say about the Event.COMPLETE event:

"Dispatched when data has loaded successfully. In other words, it is dispatched when all the content has been downloaded andthe loading has finished. The complete event is always dispatched after the init event. The init event is dispatched when the object is ready to access, thoughthe content may still be downloading."

Beginning of the complete event handler

The complete event handler that is registered in Listing 3 begins in Listing 4. This handler is executed when the load process is completeand the image data is available.

Beginning of the complete event handler.

private function completeHandler(event:Event):void{ //Get, cast, and save a reference to a Bitmap object// containing the content of the image file. var original:Bitmap = Bitmap(event.target.loader.content);//Set the width and height of the VBox object based // on the size of the original bitmap.this.width = original.width + 10; this.height = 3*original.height + 12;

Get a reference to the Bitmap object

The handler begins by using the incoming reference to the Event object to execute a complex statement that ends up with a reference to the Bitmap object. However, that reference is received as type DisplayObject and must be cast to type Bitmap to be used for its intended purpose in this program. The reference is cast to type Bitmap and saved in the variable named original .

When the first statement in Listing 4 finishes executing, the variable named original refers to a Bitmap object containing the image from the image file specified in Listing 2.

Set the dimensions of the VBox object

After creating the new Bitmap object, Listing 4 uses the dimensions of the Bitmap object to set the dimensions of the VBox object, which is shown by the yellow background in Figure 1.

Can use almost any image

All of the placement information for the images shown in Figure 1 is based on the dimensions of the Bitmap object. Therefore, you should be able to substitute any JPEG, PNG, or GIF image file in place of my file so longas the name of the file matches the name and location of the file specified in Listing 2. Note however that your image file will need to be wide enough andtall enough to prevent the magenta and green color bars added to the center image in Figure 1 from extending outside the image.

Questions & Answers

what is defense mechanism
Chinaza Reply
what is defense mechanisms
Chinaza
I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with actionscript. OpenStax CNX. Jun 04, 2010 Download for free at http://cnx.org/content/col11202/1.19
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with actionscript' conversation and receive update notifications?

Ask