Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

XML menu tree

This is a discussion on XML menu tree within the advanced Actionscript 3.0 forums, part of the Flash CS3 eng category; Hi Magdy, sorry for the late. have a look: Code: var menuArray:Array = new Array(); var menuText:TextField; var menuSubText:...


Go Back   Forum Flash CS3 Flash CS4 > English Forums > Flash CS3 eng > advanced Actionscript 3.0

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #21 (permalink)  
Old 02-01-08, 07:07
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,486
Rep Power: 6
Flep is on a distinguished road
Re: XML menu tree

Hi Magdy,
sorry for the late.

have a look:

Code:
var menuArray:Array = new Array();
var menuText:TextField;
var menuSubText:TextField = new TextField();

var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("arrays.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void
{
    var xml:XML = new XML(event.target.data);
    var myXML:XMLDocument = new XMLDocument();
    myXML.ignoreWhite = true;
    myXML.parseXML(xml.toXMLString());
    var node:XMLNode = myXML.firstChild;

    var itemArray:Array = new Array();
    var firstNode:int = node.childNodes.length;
    for (var i:int = 0; i < firstNode; i++)
    {
        itemArray.push(node.childNodes[i].attributes['NOME']);
        menuText = new TextField();
		menuText.selectable=false;
		menuText.name=i.toString();
        menuText.y = i * 20;
        menuText.text = itemArray[i];
        menuText.autoSize = TextFieldAutoSize.LEFT;
        addChild(menuText);
        menuText.addEventListener(MouseEvent.CLICK, onClick);

        var itemSubArray:Array = new Array();
        var secondNode:int = node.childNodes[i].childNodes.length;
        for (var j:int = 0; j < secondNode; j++)
        {
            itemSubArray.push(node.childNodes[i].childNodes[j].firstChild.nodeValue);
        }
        menuArray.push(itemSubArray);
    }
    menuArray.push(itemArray);
}

function onClick(event:MouseEvent):void
{
	var id:int=int(event.target.name);
	var submenus:int=menuArray[id].length;
	for(var i:int=0;i<submenus;i++)
	{
		trace(menuArray[id][i]);
	}
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #22 (permalink)  
Old 03-01-08, 20:35
Junior Member
 
Join Date: Aug 2007
Location: Brasil
Posts: 18
Rep Power: 0
Magdy is on a distinguished road
Re: XML menu tree

Hi Flep!

finally this works for me, but only when tracing.

When I click the top level menu item, I get only one subitem and it the last item of wich top level item.
If I try to create a new textfield inside the onClick for function, I´ve got all the subitems for each level, but when I click other top level item, the old subitem still remains so the new one appears on the top of the old level.

I´ll post the code with what I add:
Code:
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;

var menuArray:Array = new Array();
var menuText:TextField;
var menuSubText:TextField = new TextField();
var myTween:Tween;

var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("arrays.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void
{
    var xml:XML = new XML(event.target.data);
    var myXML:XMLDocument = new XMLDocument();
    myXML.ignoreWhite = true;
    myXML.parseXML(xml.toXMLString());
    var node:XMLNode = myXML.firstChild;

    var itemArray:Array = new Array();
    var firstNode:int = node.childNodes.length;
    for (var i:int = 0; i < firstNode; i++)
    {
        itemArray.push(node.childNodes[i].attributes['NOME']);
        menuText = new TextField();
        menuText.selectable=false;
        menuText.name=i.toString();
        menuText.y = i * 20;
        menuText.text = itemArray[i];
        menuText.autoSize = TextFieldAutoSize.LEFT;
        addChild(menuText);
        menuText.addEventListener(MouseEvent.CLICK, onClick);

        var itemSubArray:Array = new Array();
        var secondNode:int = node.childNodes[i].childNodes.length;
        for (var j:int = 0; j < secondNode; j++)
        {
            itemSubArray.push(node.childNodes[i].childNodes[j].firstChild.nodeValue);
        }
        menuArray.push(itemSubArray);
    }
    menuArray.push(itemArray);
}

function onClick(event:MouseEvent):void
{
    var id:int = int(event.target.name);
    var submenus:int = menuArray[id].length;
    for (var i:int = 0; i < submenus; i++)
    {
        menuSubText.x = 200;
        menuSubText.y = i * 20;
        menuSubText.selectable=false;
        menuSubText.text = menuArray[id][i];
        myTween = new Tween(menuText, "y", Strong.easeOut, menuText.y, menuSubText.y, 1, true);
    }
}

menuSubText.autoSize = TextFieldAutoSize.LEFT;
addChild(menuSubText);
Try testing this please...
Thank you very much for all your help!!
Bye
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #23 (permalink)  
Old 04-01-08, 06:48
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,486
Rep Power: 6
Flep is on a distinguished road
Re: XML menu tree

You have to create a new TextField for each subitem inside of onClick function.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #24 (permalink)  
Old 04-01-08, 15:56
Junior Member
 
Join Date: Aug 2007
Location: Brasil
Posts: 18
Rep Power: 0
Magdy is on a distinguished road
Re: XML menu tree

Hummmm...

I´ve tried this. I create the textfiel inside the onClick function under the for loop, becuase is the only way to get the others sub items to appear.

If I create the texfield outside the for loop, it only shows the last subitem of each top level.

When I create the textfield under the for loop, I get all the items, but there´s another problem, when I click in another top level Item of the menu, the old items remain in the stage so it looks like text over text.

Give me a Tip!
Now I have to go.
Bye
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #25 (permalink)  
Old 09-01-08, 01:02
Flash Addict
 
Join Date: Jan 2008
Location: Greece
Posts: 6
Rep Power: 0
michako is on a distinguished road
Cool Re: XML menu tree

Hi guys,

This is a concluded tree menu based on your steps!
I don't know if this is the best way to do it but its working
Sorry I don't have any time to explain it know (too much work to do)
but I will answer to your questions (or I 'll try).
Send me your feedback!!

[hey!this is my first contribute to the flash community!!! cool!!!!]
Attached Files
File Type: rar XML_TreeMenu.rar (25.3 KB, 54 views)

__________________
"έν οίδα οτι ουδέν οίδα" - Σωκράτης

Last edited by Flep; 13-05-08 at 20:06..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Flash Multi Gallery
  #26 (permalink)  
Old 09-01-08, 07:53
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,486
Rep Power: 6
Flep is on a distinguished road
Re: XML menu tree

Thank you michako ! I appreciate it

It works properly, perhaps you just need to add the MouseEvent.MOUSE_DOWN at the submenu textfields
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #27 (permalink)  
Old 09-01-08, 08:35
Flash Addict
 
Join Date: Jan 2008
Location: Greece
Posts: 6
Rep Power: 0
michako is on a distinguished road
Re: XML menu tree

Of course!
As I am working my project I have improved it a lot.
I'll post the full version if anyone asks it.
This is for the ones who need a base to begin!

Great!
Have a nice day!
__________________
"έν οίδα οτι ουδέν οίδα" - Σωκράτης
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #28 (permalink)  
Old 14-01-08, 02:58
Junior Member
 
Join Date: Aug 2007
Location: Brasil
Posts: 18
Rep Power: 0
Magdy is on a distinguished road
Re: XML menu tree

Thanks michako!!!

It´s exactly what I was wondering!!!
Thank you very much!!!

Now I will study the code to understand everything...

Again thank you very much!!
And thank you Flep for all your patience.

Bye!!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #29 (permalink)  
Old 10-03-08, 14:09
Junior Member
 
Join Date: Nov 2007
Posts: 11
Rep Power: 0
ila74 is on a distinguished road
Riferimento: Re: XML menu tree

ciao, ho scaricato il tuo menù, fantastico!!!, ma mi servirebbe anche un terzo e quarto sottolivello, come faccio ad inserirli?
grazie, ciao





Quote:
Originally Posted by hard_overclocker View Post
Hey Magdy, here is one XML menu I created for a website. Take a look at the source and perhaps you can get some help out of it. The problem is that the code is bloated with all kind of junk workarounds (my type of coding i'm afraid).
Hope this helps, if not perhaps we will have a tutorial here soon about this.

I have uploaded the code.

Happy flashing. Ciao
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #30 (permalink)  
Old 11-03-08, 15:38
Junior Member
 
Join Date: Nov 2007
Posts: 11
Rep Power: 0
ila74 is on a distinguished road
Riferimento: Re: XML menu tree

ma non funzionano i link nel menù .rar ???
come si fa?


Quote:
Originally Posted by hard_overclocker View Post
Hey Magdy, here is one XML menu I created for a website. Take a look at the source and perhaps you can get some help out of it. The problem is that the code is bloated with all kind of junk workarounds (my type of coding i'm afraid).
Hope this helps, if not perhaps we will have a tutorial here soon about this.

I have uploaded the code.

Happy flashing. Ciao
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Load directory structure in tree component fisad Flash CS3 eng 0 17-04-08 23:08
menu tree ad albero in su sk8benji Flash CS3 generale 2 01-04-08 13:45
[propagazione di eventi] menu tree pepigno75 Actionscript 3.0 avanzato 2 24-03-08 14:42


All times are GMT. The time now is 21:26.


Powered by vBulletin versione 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap


FlepStudio
by Filippo Lughi
P.IVA 03605860406