Welcome, Guest. Please login or register.
Did you miss your activation email?
02/08/12, 13:59
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  Web Services: XML, Soap, WSDL, UDDI, and Flash Integration (Moderators: Flash-db, Musicman, vesa kortelainen, Ronald Wernecke, Jorge Solis)
| | |-+  On XML menu in Flash
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: On XML menu in Flash  (Read 2780 times)
Ryan
Server what's that
*
Posts: 7



View Profile Email
« on: 04/06/03, 04:42 »

Hi to everyone,

I can't figure out how to create a very simple drop down menu using an xml external file.

Here's my code sample

Code:

menuXml = new XML();
menuXml.ignoreWhite = true


menuXml.onLoad = function(success) {

   if (success) {
      
      menuItem = this.firstChild.childNodes;
      
      for (var i=0; i<menuItem.length; i++) {
         //
         item = _root.attachMovie("itemClip", "itemClip" +i, i);
         item._x =108*i;
         item._y =108;
         item.labello = menuItem[i].attributes.name.push;
         item.menuUrl = menuItem[i].attributes.url;
         item.onRollOver = function() {
            item.SubItemClip.removeMovieClip();
         }
         //item.onRelease = function() {
            //getURL(this.menuUrl);
         //}
         trace(item);
         submenu();
         node = menuItem[i].childNodes;
         trace(node);
         for (var j=0; j < node.length; j++) {
            subitem = item.attachMovie("SubItemClip", "SubItemClip" +j, j*j+2);
            //trace(subitem)
            subitem._x = 0;
            subitem._y = -108+(14*j);
            subitem.SubItemLabel.text = node[j].attributes.name;
            subitem.SubmenuUrl = node[j].attributes.url;
            subitem.onRelease = function() {
               getURL(this.SubmenuUrl);
            }
         }
         
      }
   }
}


menuXml.load("menu.xml")


I'd like to assign it to a button which opens the submenu tree and closes it depending on which main menu item the mouse is onRollOver...
Does anyone know how to figure it out?

(sorry for my english...)

Thanx
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #1 on: 04/07/03, 02:06 »

Difficult to figure out looking your code. Anyway, using a removeMovieClip() on rollover with a bad reference doesn't do so much:

Quote

item.onRollOver = function() {
           item.SubItemClip.removeMovieClip();
}


SubItemClip is the linkage name, you need also a number, SubItemClip1 i.e. Also you're creating the submenues, but should be created on rollover event or?
There are some nice XML menues in flashcomponents net like this: http://www.flashcomponents.net/component.cfm?nav=2&id=94

Jorge
Logged

Ryan
Server what's that
*
Posts: 7



View Profile Email
« Reply #2 on: 04/07/03, 02:39 »

Yes...
The subitems have to appear when I'm on rollover on the main menu links.

You have to think that I'm just trying to create a simple drop down menu, but using XML. The script you suggested is too complicated for me at this time...

As I said the parsing is not a problem, I need some more interaction but I can't come across...

Thanks

Huh
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #3 on: 04/07/03, 03:49 »

Parsing XML is allways a complicated task. You can store subnodes references in an array and call a duplicate or attachMovie routine based on a second level of nodes on rollOver event. How looks your XML?

Jorge
Logged

Ryan
Server what's that
*
Posts: 7



View Profile Email
« Reply #4 on: 04/07/03, 03:55 »

Here's a codesample:

<menu>
<menuItem name="vfsvs" url="xxx.aspx">
 <menuSubItem name="vsdwgfs" url="xxx1.aspx" />
 <menuSubItem name="vsdwgfs" url="xxx1.aspx" />
 <menuSubItem name="vsdwgfs" url="xxx1.aspx" />
 <menuSubItem name="vsdwgfs" url="xxx1.aspx" />
</menuItem>
<menuItem name="vfsvs" url="xxx.aspx">
 <menuSubItem name="vsdwgfs" url="xxx1.aspx" />
 <menuSubItem name="vsdwgfs" url="xxx1.aspx" />
 <menuSubItem name="vsdwgfs" url="xxx1.aspx" />
 <menuSubItem name="vsdwgfs" url="xxx1.aspx" />
</menuItem>
...
</menu>

As I said, the data parsing works without problems.
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #5 on: 04/07/03, 04:14 »

Separate the submenu parsing in a function named sumenues() in example and pass a reference to a node to it. I.e:

[script]
menuXml.onLoad = function(success) {

   if (success) {
     
      menuItem = this.firstChild.childNodes;
     
      for (var i=0; i<menuItem.length; i++) {
         //
         item = _root.attachMovie("itemClip", "itemClip" +i, i);
         item._x =108*i;
         item._y =108;
         item.labello = menuItem.attributes.name.push;
         item.menuUrl = menuItem.attributes.url;
         item.node = menuItem.childNodes
         item.onRollOver = function() {
            _parent.submenues(this.node, this._y)
         }

......

function  submenues(node, y){
         for (var j=0; j < node.length; j++) {
            attachMovie("SubItemClip", "SubItemClip" +j, j*j+2);
            subitem._x = 0;
            subitem._y = y+(14*j);
            subitem.SubItemLabel.text = node[j].attributes.name;
            subitem.SubmenuUrl = node[j].attributes.url;
            subitem.onRelease = function() {
               getURL(this.SubmenuUrl);
            }
         }
         
}
[/script]

I don't have time to test the code, but you can figure the idea and fix it.

Jorge
« Last Edit: 04/07/03, 08:59 by Jorge Solis » Logged

Ryan
Server what's that
*
Posts: 7



View Profile Email
« Reply #6 on: 04/07/03, 04:46 »

Uhm...
It does not work exactly how expected.
Maybe the problem is to assign the array to a movie clip instead of a textfield?

Now it prints me out the horizontal Label, but it doesn't give me the vertical sub Items...
What do you mean with refer to submenues()? You used as function submenu(), but I can't understand where to use it...

However, I made a trace and it gives me the whole damnd think, but how to make it appear in the movie???

Sorry...
I'm getting Boring, and I'm losing my English...
but I seriously want to solve this puzzle...

Thanks
 Cry
« Last Edit: 04/07/03, 04:49 by Ryan » Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #7 on: 04/07/03, 05:26 »

Sorry, a typo. onRollover function should call submenues function.

Jorge
Logged

Ryan
Server what's that
*
Posts: 7



View Profile Email
« Reply #8 on: 04/07/03, 06:43 »

Still not working...  Cry
Logged
vesa kortelainen
Administrator
Systems Administrator
*****
Posts: 3450


View Profile
« Reply #9 on: 04/07/03, 06:44 »

Ryan as Jorge said "I don't have time to test the code, but you can figure the idea and fix it."

So, figure out yourself...

Vesa
Logged
Ryan
Server what's that
*
Posts: 7



View Profile Email
« Reply #10 on: 04/07/03, 06:48 »

I figured it out, but I can't see the error on joerg's code.
Just a matter of explain me what you mean with "refer to"...

Sorry, after this I'll stop Lips Sealed asking for help...


Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #11 on: 04/07/03, 08:59 »

When you're parsing the XML file, you build the first level tree and store in each one a reference to the next level of nodes:

item.node = menuItem.childNodes

So when rollOvers happens, this reference will passed to further parsing to the submenues function:

item.onRollOver = function() {
           _parent.submenues(this.node, this._y)
}


Also I pass the _y position of the menu item, so you can use this position to display (near or below) the second level of buttons

Jorge
Logged

Ryan
Server what's that
*
Posts: 7



View Profile Email
« Reply #12 on: 04/07/03, 09:58 »

Thanks  Grin

I found a solution with your code this afternoon, but now I realized that the path for SubItemClip does not build up the submenu... Now I'm working on it.
with a trace it prints out the subitem when I'm in the Rollover event, but seems not to work while building up the movie...
Help is of course appreciated

Here's the modified code:
Code:

menuXml = new XML();
menuXml.ignoreWhite = true
menuXml.load("menu.xml")
menuXml.onLoad = function(success) {
   if (success) {
      menuItem = this.firstChild.childNodes;
      for (var i=0; i<menuItem.length; i++) {
         //submenu();
         item = _root.attachMovie("itemClip", "itemClip" +i, i);
          item._x =108*i;
          item._y =108;
          //item.itemLabel.text = menuItem[i].attributes.name;
         item.itemLabel.text = menuItem[i].attributes.name;
         //trace(menuItem[i]);
          item.menuUrl = menuItem[i].attributes.url;
          item.node = menuItem[i].childNodes;
         trace(item.node);
          item.onRollOver = function() {
              item.submenu(this.node,this._y);
            trace(this.node);
          }
         item.onRelease = function() {
              getURL(this.menuURL);
          }
         function submenu(node) {
            for (var j=0; j<item.node.length; j++) {
               sub = _root.sub[j]
               sub.attachMovie("sub", "sub" +j, j*j+2);
               trace(item.node);
               subitem._x = 0;
               subitem._y = y+(14*j);
               subitem.SubItemLabel.text = node[j].attributes.name;
               subitem.SubmenuUrl = node[j].attributes.url;
               subitem.onRelease = function() {
                  getURL(this.SubmenuUrl);
               }
            }   
         }
      }
   }
}



Thanks for the Hint, You took the hell out of me!!!
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!