<< Chapter < Page Chapter >> Page >

A FancyButton object ISA Button object

The FancyButton class extends the Button class. Therefore, an object of the FancyButton class is also a Button object, possessing all of the characteristics of a Button . (See the earlier section titled The ISA relationship .) One of the characteristics of a Button object is the ability to have its appearance changed through the use of skinning.

Different ways to create skins

There are several different ways to create skins for ActionScript objects, including the use of images to create graphical skins . According to About Skinning ,

"When using graphical skins, you must embed the image file for the skin in your application. To specify your skin, you can use the setStyle() method,set it inline, or use Cascading Style Sheets (CSS)"

Embedding image files

There is more than one way to embed an image file in your application and I won't attempt to explain the details. (I suggest that you go to Google and search for ActionScript embed metadata tag for more information.)

The embedding syntax

The syntax that you see in Listing 5 "Imports JPEG, GIF, PNG, SVG, and SWF files at compile time."

The syntax also makes those images accessible by way of the variables that are declared immediately following each Embed tag. Therefore, the images from each of the eight image files imported in Listing 5 can bereferenced later using the eight variables declared in Listing 5.

Constructor for the FancyButton class

The constructor for the FancyButton class is shown in Listing 6.

Constructor for the fancybutton class.

public function FancyButton(){//constructor this.setStyle("upSkin", frogUp);this.setStyle("overSkin", frogOver); this.setStyle("downSkin", frogDown);this.setStyle("disabledSkin", frogDisabled); }//end constructor

The constructor calls the setStyle method four times in succession to set the four styles described earlier to the frog images imported in Listing 5. This causes the button instantiatedfrom the FancyButton class to exhibit frog skins at startup as shown in Figure 2.

The toggleSkin method

The toggleSkin method is shown in Listing 7.

The toggleskin method.

public function toggleSkin():void{ if(this.getStyle("upSkin") == frogUp){this.setStyle("upSkin", bFlyUp); this.setStyle("overSkin", bFlyOver);this.setStyle("downSkin", bFlyDown); this.setStyle("disabledSkin", bFlyDisabled);}else{ this.setStyle("upSkin", frogUp);this.setStyle("overSkin", frogOver); this.setStyle("downSkin", frogDown);this.setStyle("disabledSkin", frogDisabled); }//end else}//end toggleSkin }//end class}//end package

Called by a click event handler method

This method is called whenever the FancyButton object that was instantiated in Listing 2 fires a click event. This call results from the registration of the event handler method on the button in Listing 3 andthe definition of the event handler method in Listing 4.

Skin toggling algorithm

Listing 7 tests to determine if the button is currently exposing skins based on the frog images. If so, it uses the setStyle method to switch all four skin styles to the butterfly images.

Questions & Answers

Explain the following terms . (1) Abiotic factors in an ecosystem
Nomai Reply
Abiotic factors are non living components of ecosystem.These include physical and chemical elements like temperature,light,water,soil,air quality and oxygen etc
Qasim
what is biology
daniel Reply
what is diffusion
Emmanuel Reply
passive process of transport of low-molecular weight material according to its concentration gradient
AI-Robot
what is production?
Catherine
Pathogens and diseases
how did the oxygen help a human being
Achol Reply
how did the nutrition help the plants
Achol Reply
Biology is a branch of Natural science which deals/About living Organism.
Ahmedin Reply
what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
what is biology
Hajah Reply
cell is the smallest unit of the humanity biologically
Abraham
what is biology
Victoria Reply
what is biology
Abraham
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is respiration
Deborah
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan 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