PDA

View Full Version : Accordion and Combo-box (one more time)


AlladinYYC
10-10-2005, 06:50 PM
know i have raised this issue before but i'm still fighting with it and i would appreciate any insight. I thought that something within my application was creating a problem with in these two so i created a brand new application that just has the two components. The accordion and the combo box. Both generated dynamically. The accordion has 3 tabs... in the first tab i add a combo box. It adds fine but it doesn't respond to clicking on it... anotherwords it doesn't want to open.

Please try it out: copy the following code into a new file and add the accordion and the combobox to your library.

Another thing to mention too is that when i added an "open" listener - it does catch... it says that it's opened when the arrow is pressed... but you can see it


import mx.containers.Accordion;
import mx.controls.ComboBox;
import mx.core.View;
//
this.onLoad = function() {
//
createClassObject(Accordion, "menuAccordion", _root.getNextHighestDepth());
_root.menuAccordion.setStyle("themeColor", "haloOrange");
_root.menuAccordion.move(0, 0);
_root.menuAccordion.setSize(550, 400);
_root.menuAccordion.setStyle("backgroundColor", "0xFDFDFD");
//create tabs
_root.menuAccordion.createChild(View, "fileAccordion", {label:" File..."});
_root.menuAccordion.createChild(View, "lessonAccordion", {label:" Lesson Options"});
_root.menuAccordion.createChild(View, "paragraphAccordion", {label:" Paragraph Content"});
//
_root.menuAccordion.fileAccordion.createEmptyMovie Clip("paragraphContainer", 0);
//question type selection
_root.menuAccordion.fileAccordion.paragraphContain er.createTextField("questionTypeText", _root.menuAccordion.paragraphAccordion.paragraphCo ntainer.getNextHighestDepth(), 50, 20, 320, 20);
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeText.type = "static";
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeText.selectable = false;
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeText.htmlText = "Question Type:";
//
_root.menuAccordion.fileAccordion.paragraphContain er.createClassObject(ComboBox, "questionTypeInputText", _root.menuAccordion.paragraphAccordion.paragraphCo ntainer.getNextHighestDepth());
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText.move(170, 20);
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText.setSize(150, 22);
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText.dataProvider = [{label:"Multiple Choice", data:"multiplechoice"}, {label:"True or False", data:"trueorfalse"}, {label:"Fill in the Blank", data:"fillintheblank"}];
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText.enabled = true;
//
var cbListener:Object = new Object();
cbListener.change = function(evt_obj:Object):Void {
var currentlySelected:Object = evt_obj.target.selectedItem;
trace(evt_obj.target);
trace("data: "+currentlySelected.data);
trace("label: "+currentlySelected.label);
};
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText.addEventListener("change", cbListener);
var cbListener2:Object = new Object();
cbListener2.open = function(evt_obj:Object):Void {
trace("I opened");
var currentlySelected:Object = evt_obj.target.selectedItem;
trace(evt_obj.target);
trace("data: "+currentlySelected.data);
trace("label: "+currentlySelected.label);
};
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText.addEventListener("open", cbListener2);
};

Paerez
10-10-2005, 07:02 PM
You have to use lockroot on comboboxes sometimes. Don't worry, it won't mess up using root (except if you attach a movie clip inside the combobox movie clip and referenced root, but who does that?? besides you could just use _parent._root).

_root.menuAccordion.fileAccordion.paragraphContain er.createClassObject(ComboBox, "questionTypeInputText", _root.menuAccordion.paragraphAccordion.paragraphCo ntainer.getNextHighestDepth());
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText._lockroot = true;
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText.move(170, 20);
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText.setSize(150, 22);
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText.dataProvider = [{label:"Multiple Choice", data:"multiplechoice"}, {label:"True or False", data:"trueorfalse"}, {label:"Fill in the Blank", data:"fillintheblank"}];
_root.menuAccordion.fileAccordion.paragraphContain er.questionTypeInputText.enabled = true;

AlladinYYC
10-10-2005, 07:15 PM
Wow... that's great. Thanks so much. Do you know why this is happening and why i need to set _lockroot here? All the other components seem to work fine...

Alina

Paerez
10-10-2005, 07:49 PM
Combo boxes are a combination of a text field, a button, and a list component. When you make a combo box it does something using _root to attach its components to make the whole box. So what was happening is probably a depth collision with the accordion component.

What lockroot does (which is actually kind of handy for your own movie clips some times) its locks the root to the scope it is called from. It is like making a glass ceiling.

Lets say you have 5 movie clips:
mc1.mc2.mc3.mc4.mc5

All nested in each other. Then you do:
mc1.mc2.mc3._lockroot = true;

then, mc1.mc2.mc3.mc4.mc5._root will give you mc1.mc2.mc3 as "root" because there is this glass ceiling that it hits on the way up and stops.
If you want to break through, you can do this:
mc1.mc2.mc3.mc4.mc5._root._parent._root
and that will return you to the next ceiling.

So if you put lockroot on mc2 and mc3, the _root._parent._root line will bring you to mc2.

time to bring it full circle:
The combobox uses _root, hits the glass ceiling at itself (like it is root) and attaches everything appropriately.

Hella confusin' though huh?

AlladinYYC
10-10-2005, 10:32 PM
No kidding... but it makes sense! :rolleyes: :D

Thank you,

Alina