Knowledge Base |
Important! All new questions are usually answered within the next business day.
Accordion (Tree) Menu V3
(views: 18228)
Accordion Menu V3 and Accordion Tree Menu V3 are xml flash accordion menus featuring customized states, customized transitions and tweens. Here are all known issues for Accordion Menu V3 and Accordion Tree Menu V3, they should be similar, since basically it is the same component. If you have any questions that you think we should discuss here please let us know.
How do I add the AccordionTreeMenuV3AS3 from class file to stage
(2007-11-14 - views: 3979)
Q: I'm sure this is possible but I am just learning AS3 and I need to be able to add this component to the stage with a button click, passing in a variable that contains the xml for the menu. I have parsed a huge xml file in my class file and have broken it down into 4 new xml objects with each xml object being the navigation for each of the 4 buttons I have.
So for example I have a button on stage called "buttonOne". I also have an XML object called "buttonOneXML". I would like to add the AccordionTreeMenuV3AS3 to the stage when "buttonOne" is pressed and tell it to use "buttonOneXML" as it's source.
Please help, this is a fairly urgent request and I cannot find any documentation on adding the component at run-time.
So for example I have a button on stage called "buttonOne". I also have an XML object called "buttonOneXML". I would like to add the AccordionTreeMenuV3AS3 to the stage when "buttonOne" is pressed and tell it to use "buttonOneXML" as it's source.
Please help, this is a fairly urgent request and I cannot find any documentation on adding the component at run-time.
A: Here is the script you have to adapt to your project.
import flash.events.MouseEvent;
import com.jumpeye.Events.AccordionMenuEvents;
var acc:AccordionTreeMenuV3AS3;
//create a listener, to find when the button is pressed
buttonOne.addEventListener(MouseEvent.MOUSE_DOWN, buttonOnePress);
function buttonOnePress(event:MouseEvent):void
{
// when the button is pressed, we call de attachMenu function to create another AccordionTreeMenuV3AS3
attachMenu("buttonOneXML.xml");
}
// the function that attach a new AccordionTreeMenuV3AS3.
function attachMenu(xm:String):void
{
// if another menu already exist, we remove it.
if(acc != null)
this.removeChild(acc);
// we create the menu.
acc = new AccordionTreeMenuV3AS3();
// set the xml for the menu.
acc.xmlPath = xm;
//we set a random position, to know that a new menu was created.
acc.x = Math.random()*350;
//and finaly, we add the menu on the stage.
this.addChild(acc);
// we need to know when the menu has finished drawing itself on the stage,
// because only than can we set the width property (which does not exist
// until then).
acc.addEventListener(AccordionMenuEvents.DRAW, drawHdl);
}
// after the entire component has been drawn, we can set the width of the menu.
function drawHdl(evt:AccordionMenuEvents):void {
acc.width = 200;
}
import flash.events.MouseEvent;
import com.jumpeye.Events.AccordionMenuEvents;
var acc:AccordionTreeMenuV3AS3;
//create a listener, to find when the button is pressed
buttonOne.addEventListener(MouseEvent.MOUSE_DOWN, buttonOnePress);
function buttonOnePress(event:MouseEvent):void
{
// when the button is pressed, we call de attachMenu function to create another AccordionTreeMenuV3AS3
attachMenu("buttonOneXML.xml");
}
// the function that attach a new AccordionTreeMenuV3AS3.
function attachMenu(xm:String):void
{
// if another menu already exist, we remove it.
if(acc != null)
this.removeChild(acc);
// we create the menu.
acc = new AccordionTreeMenuV3AS3();
// set the xml for the menu.
acc.xmlPath = xm;
//we set a random position, to know that a new menu was created.
acc.x = Math.random()*350;
//and finaly, we add the menu on the stage.
this.addChild(acc);
// we need to know when the menu has finished drawing itself on the stage,
// because only than can we set the width property (which does not exist
// until then).
acc.addEventListener(AccordionMenuEvents.DRAW, drawHdl);
}
// after the entire component has been drawn, we can set the width of the menu.
function drawHdl(evt:AccordionMenuEvents):void {
acc.width = 200;
}
User Comments
runtime add AccordianTreeMenuV3 for AS2?
Can you show an example of how to add the AccordianTreeMenuV3 AS2 version of the component at runtime ? Many thanks....I didn't see an example yet.
posted by W on 2007-11-14
Can you show an example of how to add the AccordianTreeMenuV3 AS2 version of the component at runtime ? Many thanks....I didn't see an example yet.
AS2 version
W
Se this :P
<a href='https://www.jumpeyecomponents.com/knowledgebase/Accordion-%28Tree%29-Menu-V3/How-do-I-add-the-AccordionTreeMenuV3-on-stage-in-runtime%3F~181/'>here</a>
posted by demiurgu on 2007-11-15
W
Se this :P
<a href='https://www.jumpeyecomponents.com/knowledgebase/Accordion-%28Tree%29-Menu-V3/How-do-I-add-the-AccordionTreeMenuV3-on-stage-in-runtime%3F~181/'>here</a>
Answer for jbmurphy
Hi
You should use setXML(xmlObject:XML) method .
After you've added the component, instead of using the xmlPath parameter:
acc.xmlPath = xm;
you have to write this :
acc.setXML(xmlObject) where xmlOject is your xml object
posted by demiurgu on 2007-11-15
Hi
You should use setXML(xmlObject:XML) method .
After you've added the component, instead of using the xmlPath parameter:
acc.xmlPath = xm;
you have to write this :
acc.setXML(xmlObject) where xmlOject is your xml object
That worked well, thank you.
Just a quick note for anyone who uses the component as I have, make sure that when you are creating an XML object in your class file that you give a "title" attribute to each item node, even if it's title="", otherwise you will get a setText() error.
posted by jbmurphy on 2007-11-15
Just a quick note for anyone who uses the component as I have, make sure that when you are creating an XML object in your class file that you give a "title" attribute to each item node, even if it's title="", otherwise you will get a setText() error.
perfectly true
That's right
Thanks for bringing this to our attention. We will fix it in the next release :)
posted by demiurgu on 2007-11-16
That's right
Thanks for bringing this to our attention. We will fix it in the next release :)
can i load .swfs into each XML node?
I bought this for a very specific project. The nav uses Arial and needs to have a significant amount of letter spacing. Your answer to my last question was that letter kerning was not possible with this component - with no solution. How can I work around this? could i load .swfs into each XML node? Can I alter anything with actionscript in the movie the component is loaded into? The beauty of working in flash is that nothing has to look like html anymore. I need a solution, please help!
posted by acillustration on 2008-02-13
I bought this for a very specific project. The nav uses Arial and needs to have a significant amount of letter spacing. Your answer to my last question was that letter kerning was not possible with this component - with no solution. How can I work around this? could i load .swfs into each XML node? Can I alter anything with actionscript in the movie the component is loaded into? The beauty of working in flash is that nothing has to look like html anymore. I need a solution, please help!
Login to post your comment



I sincerely hope this is possible, but it might not be which would render this component useless for me in this application, but ... instead of an actual physical xml file I have an xml object that I have created through actionscript that traces out exactly as this component requires.
Please tell me that it is possible to do this with this component.