Archive for February, 2005

flash mx 2004: Quick fix for setting the fontSize of the Accordion component

Friday, February 25th, 2005

I’ve been using macromedia’s livedocs site for the past couple of months as a major resource to research actionscript code. So yesterday when it came time to changing the font size on my Accordion component I referenced my trusty Macromedia livedoc page “Customizing the Accordion component”. Macromedia documents that to change the font size of the accordion you only need to use the following code:

myComponentInstance.setStyle(”fontSize”, 9);

So for an hour I wondered why the hell my font size was still the default setting. It had worked for my Tree component and my Button component I had used just weeks before. Was I going mental? No.

Solution:

So I decided to test my movie, go to Menu, Debug, and List Variables to see what was going on.

That’s where I found the Variable AccordionHeader and along beside it were it’s global styles listed.

Went back to my actions and tried:

_global.styles.AccordionHeader.setStyle(”fontSize”, 9);

I tested the movie and it worked!

If you have trouble setting other styles with your Accordion component try using the above code for other styles such as fontWeight, color, etc.

flash mx 2004: Dynamically creating the sequence of children for your Accordion component from a XML file

Thursday, February 24th, 2005

For the past couple of days I’ve been working on developing a creative way to show Progress summaries for all the chapters in the courseware I have been developing. Instead of having a long list of Chapter and Topic titles listed and their respective progress status displayed, I decided to use the Accordion component to organize and display my individual Progress summaries. In the words of Macromedia the Accordion component is a navigator that contains a sequence of children that it displays one at a time.

However I needed the children for my Accordion to be dynamically created based on information from a XML file.

Solution:

Open a new .fla document and save it as accordion.fla. From the Components panel drag the Accordion component on to your timeline and assign it the instance name myAccordion.

Now create your XML file in Dreamweaver. For this sample, use the following code and save your file as accordion.xml in the same directory as your newly created fla file.

<node>
<node label=”Label One” />
<node label=”Label Two” />
<node label=”Label Three” />
<node label=”Label Four” />
<node label=”Label Five” />
<node label=”Label Six” />
</node>

Now back to Flash. Create a new layer and call it Actions. Select the first key frame in this layer and insert the following actionscript.

myXML = new XML();
myXML.ignoreWhite = true;
myXML.load(”accordion.xml”);

We have just created a new XML object and loaded the XML-formatted data (accordion.xml) from an external source. myXML.ignoreWhite is set to true so that all white space in the XML document is ignored when the data is parsed.

Now insert the following actionscript directly below.

myXML.onLoad = function() {
var i:Number = myXML.firstChild.childNodes.length;
for (var n=1; n

If you don’t know what the above actionscript is all about then continue reading.

What this does is create a child for each node in the XML document on our Accordion component that we assigned the instance myAccordion to.

First we need to determine the number of childNodes in the firstChild of the XML file and assign that number a variable called i. In this example, ‘i’ should return a value of 6.

var i:Number = myXML.firstChild.childNodes.length;

Next we will create a loop.

for (var n=1; n

Notice that the number of iterations that the loop will perform (variable i), is the number of childNodes in the firstChild of the XML file.

We will now have to perform the following actions inside the loop.

var accordionLabel:String = myXML.firstChild.childNodes[n-1].attributes.label;
myAccordion.createChild(”View”, n, {label:accordionLabel});

First we determine the value of the node label in the XML file and assign it a variable called accordionLabel. We’ve used the variable “n” to also change the childNode number and create a different childInstanceName each time the loop is performed. Keep in mind that to reference the first childNode always use zero. That’s why we have “n-1”

After we create the variable “accordionLabel” we can now create the child with an instance name based on the variable “n”, and a label based on the variable “accordionLabel”.

Save and test movie.

Click here to download example files.

flash mx 2004: Setting the wordWrap on the Checkbox component

Wednesday, February 23rd, 2005

Today I had to create a quiz for my elearning project at work and given the deadline I was under I decided to try out Flash’s Quiz templates.

I noticed that if my “Answer” text was too long the Checkbox label wouldn’t automatically wrap it.

Solution:

In the same key frame and timeline that your Checkbox resides, add the following actionscript.

this.myCheckbox.labelPath.wordWrap = true;
this.myCheckbox.labelPath.multiline = true;

Remember to change the height of your Checkbox component to accommodate the additional lines of text. If you don’t, you will only see one line of text when you test or publish your movie.

labelPath actually has quite a few properties associated with it (ie. html, _width, _height, etc.). When you test your movie and select “Debug/List Variables” search for the string _level0.myCheckbox.labelPath. If you view the output before adding the above actionscript you will notice that the default setting for wordWrap and multiline is set to false.