<< Chapter < Page Chapter >> Page >

The constructor for the Driver class is shown in its entirety in Listing 4.

The constructor for the driver class.

public function Driver(){//constructor //Load the sky image.//Note the use of a / to eliminate the "Unable to // resolve asset for transcoding" Compiler Error[Embed("/smallsky.jpg")] var imgSmall:Class;smallSky.load(imgSmall);//Load four sound files and play two of them now. sizzle = new Sound();sizzle.load(new URLRequest("sizzle.mp3"));thunder = new Sound();thunder.load(new URLRequest("thunder.mp3"));wind = new Sound(); wind.load(new URLRequest("wind.mp3"));//Play the wind sound through twice at startup. wind.play(0,2);rain = new Sound();rain.load(new URLRequest("rain.mp3")); //Play the rain sound foreverrain.play(0,int.MAX_VALUE);//Register an event listener on the CREATION_ // COMPLETE event.this.addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);} //end constructor

There are quite a few things in Listing 4 that are new to this lesson.

Embed the image file

Although the code required to embed the image file in the swf file is not new to this lesson, it is worth highlighting the need to include the slash characterto make the code compatible with the FlashDevelop IDE.

Load the sizzle sound

Listing 4 instantiates a new Sound object and stores the object'sreference in the instance variable named sizzle . Then it calls the load method on that object to load the contents of the sound file named sizzle.mp3 into the new Sound object.

The load method of the Sound class

Here is part of what the documentation has to say about the load method of the class named Sound :

"Initiates loading of an external MP3 file from the specified URL. If you provide a valid URLRequest object to the Sound constructor, theconstructor calls Sound.load() for you. You only need to call Sound.load() yourself if you don't pass a valid URLRequest object to the Sound constructor oryou pass a null value.
Once load() is called on a Sound object, you can't later load a different sound file into that Sound object. To load a different sound file,create a new Sound object."

Because I didn't provide a URLRequest object to the constructor when I instantiated the object of the Sound class, it was necessary for me to call the load method on the Sound object to load the sound file named sizzle.mp3 .

Required parameter for the load method

Only one parameter is required by the load method and it must be of type URLRequest . To make a long story short, at least for the case where the sound file is located in the src folder as shown in Figure 2, you can create the required URLRequest object by calling the constructor for the URLRequest class and passing the name of the sound file as a String parameter to the constructor as shown in Listing 4.

Don't play the sizzle sound yet

The sizzle sound and the thunder sound are both encapsulated in Sound objects by the constructor in Listing 4. However, those sounds are not played bythe constructor.

Questions & Answers

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
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
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