<< Chapter < Page Chapter >> Page >

Lots of comments

As you can see, I included lots of comments in Listing 4 in an attempt to make it as self-explanatory as possible.

In this lesson, I will concentrate on the differences between this Flex 4 project and the Flex 3 project named Namespace01 that arise from creating the two projects using different versions of Flex.

Order of attributes is not important

Let me begin by explaining that in XML, the order in which you write the attributesfor an element doesn't matter so long as they are all there with the correct syntax, the correct names, and the correct values.

More and different namespace attributes

As I explained earlier, a Flex 4 project often has three required namespace attributes and almost always has two. (Because I didn't use any mx components in this program, I could have removed the namespace attribute named mx from Listing 4.)

Other than the namespace attributes, the application element in Listing 4 has the same attribute names and values as the application element in Listing 3.

No VBox element in Namespace02

The next thing to notice is that there is no mx:VBox element in Listing 4. Instead, there is an s:Group element (a Flex 4 Spark component) that replaces the mx:VBox element and serves as a container for the labels and the buttons.

No backgroundColor attribute

The s:Group element has two positioning attributes that cause it to appear in the center of the Flash Playerwindow, but it does not have an attribute named backgroundColor . Like many of the Spark components, and unlike many of the mx components, the s:Group element does not have built-in attributes that are used to control its appearance. Instead, other ways must be found to control theappearance of many Spark components.

A red rectangle

In this case, Listing 4 causes the s:Group element to appear to have a red background by causing it to contain a red rectangle of exactly the right dimensions to completely fillthe s:Group element. This produces the red background color in the upper portion of Figure 2.

As with Figure 1, the lower portion of Figure 2 also has a red background color, but it is covered by another smaller rectangle with an opaque cyan color.

Add an s:VGroup container

Then Listing 4 adds a Spark s:VGroup container to serve essentially the same purpose as the mx:VBox container in Listing 3 (except that it doesn't control the red background color) . The following elements are added tothe s:VGroup element in Listing 4 In a manner very similar to Listing 3:

  • s:Label
  • s:Button
  • MyComps:Label
  • MyComps:Button

The first two elements in the above list are Spark elements having similar characteristics to the mx elements having the same names.

The last two elements in the above list are custom components having similar characteristicsto the custom components having the same names in the earlier program.

Contents of the file named Label.mxml

The contents of the custom component file named Label.mxml are shown in Listing 5.

Contents of the file named label.mxml.

<?xml version="1.0" encoding="utf-8"?><!--Create a custom label by putting a Spark Label in a Spark Group--><s:Group xmlns:MyComps="customComps.*" xmlns:fx="http://ns.adobe.com/mxml/2009"xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"><s:Label text="Custom Label"color="#FFFF00" fontSize="12"fontWeight="bold"/></s:Group>

Contents of the file named Button.mxml

The contents of the custom component file named Button.mxml are shown in Listing 6.

Contents of the file named button.mxml.

<?xml version="1.0" encoding="utf-8"?><!--Create a custom component by putting a Spark Label and a Spark Button in a Spark VGroup inside of a SparkGroup with a Cyan background color.--><s:Group xmlns:MyComps="customComps.*" xmlns:fx="http://ns.adobe.com/mxml/2009"xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx"><!--Fill the entire group with a cyan rectangle--><s:Rect width="100%" height="100%"><s:fill><s:SolidColor color="0x00FFFF" /></s:fill></s:Rect><!--Put a Spark VGroup in the Group and put a Spark Label and a Spark Button in the VGroup--><s:VGroup><s:Label text="Custom Component."color="#000000" fontSize="12" fontWeight="bold"/><s:Button label="Button"/></s:VGroup></s:Group>

No further explanation needed

Assuming that you understand the contents of the files named Label.mxml and Button.mxml in the Flex 3 program in the earlier lesson, and assuming that you understood the explanation of thedifferences between the two main mxml files given above, the comments in Listing 5 and Listing 6 should serve as a sufficient explanation of the code in Listing5 and Listing 6.

Run the program

I encourage you to run this program from the web. Then copy the code from Listing 4 through Listing 6. Use that code tocreate your own projects. Compile and run the projects. Experiment with the code, making changes, and observing the results of your changes. Makecertain that you can explain why your changes behave as they do.

Resources

I will publish a list containing links to Flex resources as a separate document. Search for Flex Resources in theConnexions search box.

Miscellaneous

This section contains a variety of miscellaneous materials.

Housekeeping material
  • Module name: XML - Namespaces - Flex 4
  • Files:
    • Flex0086a\Connexions\FlexXhtml0086a.htm
PDF disclaimer: Although the Connexions site makes it possible for you to download a PDF file for thismodule at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should beaware that some of the HTML elements in this module may not translate well into PDF.

-end-

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Introduction to xml. OpenStax CNX. Dec 02, 2014 Download for free at https://legacy.cnx.org/content/col11207/1.18
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Introduction to xml' conversation and receive update notifications?

Ask