PDA

View Full Version : dynamically creating UIScrollBar


badger
01-18-2006, 01:01 AM
Hello all!

I'm using the Dynamically Attaching Components Tutorial (#40) and trying to output the contents of an XML file with each element having its own scrollbar. (I used the XML tutorials to get this far, too.) The XML file is a glossary so it has the word, a definition, and then a sample piece of code - all of which are different lengths. The Actionscript loops through the array and outputs the word, definition and code in a row. I was hoping to use the scrollbar component so I could keep the rows the same height and let the user scroll through the definition to read it.

However, all I'm getting is a 'blank' scrollbar on the far left-hand side of my movie and no arrows. I viewed my objects in the debugging output and found that only one scrollbar (the final one) is being created.

I reviewed the Flash Actionscript live docs and found that I needed to use UIScrollBar as the component name and not FScrollBarSymbol as in the tutorial also. Are there other changes in Flash 8?

Can anyone give me some additional guidance on how to complete this (dynamically creating multiple scrollbars with actionscript)? My code's below:

stop();
//loop through array of words, defs, and codes loaded from XML file in previous frame
for (var i=0; i<thisXML; i++) {
//create word text box - no scrollbar needed
_root.createTextField("field_txt"+i, _root.getNextHighestDepth(), 20, i*50, 100, 40);
_root["field_txt"+i].textColor = 0x0000FF;
_root["field_txt"+i].autoSize = none;
_root["field_txt"+i].text = words[i];
_root["field_txt"+i].html = true;
_root["field_txt"+i].htmlText = "<ul><a href=\"asfunction:function, param\">"+ words[i] + "</a></ul>";

//create def textbox
_root.createTextField("def_txt"+i, _root.getNextHighestDepth(), 120, i*50, 200, 50);
_root["def_txt"+i].autoSize = none;
_root["def_txt"+i].multiline = true;
_root["def_txt"+i].wordWrap = true;
_root["def_txt"+i].text = defs[i];
_root["def_txt"+i].scroll = true;

//Create scrollbar for def textbox
initialization={_targetInstanceName:_root["def_txt"+i], horizontal:false};
_root["def_txt"+i].attachMovie()"UIScrollBar", ["def_txt"+i]. 2, initialization;

//create code textbox- scroll bar will be added
_root.createTextField("code_txt"+i, _root.getNextHighestDepth(), 350, i*50, 200, 100);
_root["code_txt"+i].autoSize = none;
_root["code_txt"+i].multiline = true;
_root["code_txt"+i].wordWrap = true;
_root["code_txt"+i].text = codes[i];
_root["code_txt"+i].scroll = true;
}

Sorry for the long post!
Badger

pan69
01-18-2006, 02:15 AM
To create instances of v2 components at runtime use the createObject and the createClassObject methods defined in the UIObject class instead of attachMovie. See the Macromedia Flash help for more detail.