Log in

View Full Version : Should be Simple: Can't connect to .XML file for Dynamic Menu



JenJ
12-18-2008, 12:29 AM
Hi -
Starting to feel like I'm wasting away after 24 hours of Googling something that I'm guessing a flash developer would probably just "know".

Quick background: I downloaded a template (go figure), but seriously - I've used other Flash templates with great success in building simple sites for family. This template is kicking my butt in getting the menus to work and I really need help figuring it out. -NOTE: The Menu never worked - even download; the developer of the template did not include the 'right' script from what I can understand at this point.

The Flash portion is for the header of the site with a dynamic menu for navigating the site.
I have the .fla file, and have identified (with some strain) the 'button' area where the script is located; I have a Separate Action Script file called 'menu.as'; and I have the .xml file, called 'menu.xml'.

The menu.xml file script (simple):
**************************
<menu>
<entry label="HOME" url="http://www.helenajuhasz.com"/>
<entry label="PORTFOLIO" url="/index_sub3.html"/>
<entry label="ABOUT US" url="/index_sub.html"/>
<entry label="SOLUTION" url="/index_sub4.html"/>
<entry label="NEWS" url="/index_sub4.html"/>
<entry label="CONTACT" url="/index_sub2.html"/>
</menu>
**************************

The menu.as file script:
**************************
var feed_xml:XML = new XML();
feed_xml.ignoreWhite = true;
xml_loader._xscale = 0;
feed_xml.load("menu.xml");
feed_xml.onLoad = function(success) {
import mx.xpath.XPathAPI;
_global.menu_array = XPathAPI.selectNodeList(feed_xml.firstChild, "/menu/entry");
for (i=0; i<menu_array.length; i++) {
_global.menu_array[i].label = menu_array[i].attributes.label;
_global.menu_array[i].url = menu_array[i].attributes.url;
}
_root.movie_loading();
};

**************************

The .fla script - where I believe I'm missing the necessary pieces:
**************************
on (release) {
if (this._parent.sel != this)
{
gotoAndStop ("s3");
this._parent.rel();
this._parent.sel = this;
getURL("","_blank", "GET")
};

**************************

I contacted the company that hosted the template, and their suggestion was to just type in the URL like this:
getURL("http://www.mysite.com","_blank","GET")
While - yes this is functional - it destroys the purpose of a menu, as it limits all the buttons to one link, rather than dynamic links that are derived from the .xml file.

I've tinkered for days, but without true understanding of what I'm doing (self-taught - so I get some stuff, but am missing huge amounts of knowledge still :o), I don't want to just dive in and tear through the code.
Can you help at all?

Thanks!!!

Jen

JenJ
12-19-2008, 05:09 PM
No one else knows what to do, eh?

JenJ
12-19-2008, 11:24 PM
It's rough - but I'm getting closer to a solution. Can anyone help me get to the next step?

Script now reads:
on (release) {
if (this._parent.sel != this)
{
gotoAndStop ("s3");
this._parent.rel();
this._parent.sel = this;
if (onRelease.label="HOME") getURL("http://www.helenajuhasz.com", "_self", "GET");
if (onRelease.label="PORTFOLIO") getURL("http://www.helenajuhasz.com/index_sub3.html", "_self", "GET");
if (onRelease.label="ABOUT US") getURL("http://www.helenajuhasz.com/index_sub.html", "_self", "GET");
if (onRelease.label="SOLUTION") getURL("http://www.helenajuhasz.com/index_sub4.html", "_self", "GET");
if (onRelease.label="NEWS") getURL("http://www.helenajuhasz.com/index_sub4.html", "_self", "GET");
if (onRelease.label="CONTACT") getURL("http://www.helenajuhasz.com/index_sub2.html", "_self", "GET");
};
}


It FINALLY opens all the links, but it opens them all at once, regardless of which 'link' you select. So if I click 'Home' it opens everything, in unique windows.

Any ideas how to get it to just recognize the one I've selected?
Thanks!
Jen

JenJ
12-23-2008, 12:21 AM
Okay - I've taken it another step (days of just logically thinking this through), I'm still stuck with all pages loading all at once when you select any of the menu items.
See below - is there any way to set a parameter that says 'one link at a time'?


on (release) {
if (this._parent.sel != this)
{
gotoAndStop ("s3");
this._parent.rel();
this._parent.sel = this;
this.getNextHighestDepth()
for (i=0; i<_global.menu_array.length; i++)
getURL(_global.menu_array[i].url, "_blank", "POST");
};
}

BLiZZaRD
12-23-2008, 03:15 PM
It's always difficult for a programmer to look at anothers work and figure it out. And then we (as the 'helpers' on this forum) are at an even further disadvantage as we can't see the whole picture, just the snippets you provide.

For example, the on click functions take an MC to frame s3, but what is on that frame? Perhaps some left over testing code? a broken function? I don't know.

Seeing the whole thing would help greatly ;)

JenJ
12-23-2008, 03:42 PM
Fair enough! I wasn't sure how best to show the code, as it's mostly in a .fla file, and then broken up into different areas throughout the document.

If you know the answer for making the menu play just one page at a time, would you be willing to take a minute and tell me the logic behind the solution?

Thanks!

Jen

*******************************************************
.FLA FILE
***********
*Scene 1
** Layer 2 : Frame 1
#include "menu.as"
stop();
var my_cm:ContextMenu = new ContextMenu ();
my_cm.hideBuiltInItems ();
my_cm.builtInItems.print = true;
this.menu = my_cm;
movie_loading=function(){
//goto frame 2 where flash movie initialize or preloader function start
gotoAndStop(2);
}


** Layer 2 : Frame 2

stop ();
txtPercentage = Math.round (_root.getBytesLoaded () / _root.getBytesTotal () * 100);
this.onEnterFrame = function ()
{
tellTarget ("loader")
{
per_txt.text = Math.round ((_root.getBytesLoaded () / _root.getBytesTotal ()) * 100);
gotoAndPlay (Math.round ((_root.getBytesLoaded () / _root.getBytesTotal ()) * 100));
}
if (_root.getBytesLoaded () == _root.getBytesTotal ())
{
delete this.onEnterFrame;
play();
}
};

*Scene 2
** Script : Frame 1
stop()

*Symbol Definition(s)
** main
*** Script : Frame10
this.menu_mc.play

*** Script : Frame 100
stop ();


** but
on (rollOver) {

if (this._parent.sel != this)
{
this.gotoAndPlay ("s1");
this.allC_mc.addC();
}
}
on (rollOut) {
if (this._parent.sel != this)
{
this.gotoAndPlay ("s2");
this.allC_mc.decr();

}
}
on (releaseOutside) {if (this._parent.sel != this){
gotoAndPlay ("s2");}
}

on (release) {
if (this._parent.sel != this)
{
gotoAndStop ("s3");
this._parent.rel();
this._parent.sel = this;
for (i=0; i<_global.menu_array.length; i++)
{
getURL(menu_array[i].url);
}
};
}


** sprite 6
*** Action Layer : Frame 1

** menu
*** script : Frame 1
stop ()


*** script : Frame 2
this._parent.stop()


*** script : Frame 44
this._parent.play();


*** script : Frame 100
stop()


** buts
import mx.transitions.*;
var sel:MovieClip;
//shift x
_global.shx = 62;
//shift y
_global.shy = 30;
//standart width
_global.wi = 178;
//standart height
_global.he = 27;
//same width
_global.sw = true;
//separator
_global.sep = 1;
//horizontal
_global.hz = false;
//align
_global.as = "left";
//border
_global.br = 62;
function buts()
{
for (i=0; i<_global.menu_array.length; i++)
{
this.attachMovie("but","b"+i,this.getNextHighestDepth());
}
}
function labels()
{
for (i=0; i<_global.menu_array.length; i++)
{
this["b"+i].overTX_mc.t_txt.text = _global.menu_array[i].label;
this["b"+i].outTX_mc.t_txt.text = _global.menu_array[i].label;
this["b"+i].t_txt.text = _global.menu_array[i].label;
}
}
function rel()
{
sel.gotoAndPlay("s2");
}
function setSB1()
{
for (i=0; i<_global.menu_array.length; i++)
{
if (_global.sw)
{
this["b"+i].all_mc._width = _global.wi;
this["b"+i].bm_mc._width = _global.wi;
this["b"+i].fon_mc._width = _global.wi;
this["b"+i].bl_mc._width = _global.wi;
}
else
{
this["b"+i].all_mc._width = this["b"+i].overTX_mc.t_txt._width+_global.br;
this["b"+i].bm_mc._width = this["b"+i].overTX_mc.t_txt._width+_global.br;
this["b"+i].fon_mc._width = this["b"+i].overTX_mc.t_txt._width+_global.br;
this["b"+i].bl_mc._width = this["b"+i].overTX_mc.t_txt._width+_global.br;
}
this["b"+i].all_mc._height = _global.he;
this["b"+i].bm_mc._height = _global.he;
this["b"+i].fon_mc._height = _global.he;
}
}
function txt(type)
{
for (i=0; i<_global.menu_array.length; i++)
{
this["b"+i].overTX_mc.t_txt.autoSize = type;
this["b"+i].outTX_mc.t_txt.autoSize = type;
//this["b"+i].overTX_mc.t_txt.border = true;
//this["b"+i].outTX_mc.t_txt.border = true;
}
}
function pos()
{
for (i=0; i<_global.menu_array.length; i++)
{
if (i>0)
{
if (hz)
{
this["b"+i]._x = this["b"+(i-1)]._x+(this["b"+(i-1)].all_mc._width+this["b"+i].all_mc._width)/2+_global.sep;
this["b"+i]._y = _global.shy;
}
else
{
//this["b"+i]._y = this["b"+(i-1)]._y+(this["b"+(i-1)].all_mc._height+this["b"+i].all_mc._height)/2+_global.sep;
this["b"+i]._y = this["b"+(i-1)]._y+this["b"+i].all_mc._height+_global.sep;
trace("y"+i+" = "+this["b"+i]._y+"\t"+"H"+i+" = "+this["b"+i].all_mc._height+" "+this["b"+i]._height);
this["b"+i]._x = _global.shx;
}
}
else
{
this["b"+i]._x = _global.shx;
this["b"+i]._y = _global.shy;
}
}
}
buts();
labels();
txt(_global.as);
setSB1();
pos();


*******************************************************
MENU.AS FILE
***********
var feed_xml:XML = new XML();
feed_xml.ignoreWhite = true;
xml_loader._xscale = 0;
feed_xml.load("menu.xml");
feed_xml.onLoad = function(success) {
import mx.xpath.XPathAPI;
_global.menu_array = XPathAPI.selectNodeList(feed_xml.firstChild, "/menu/entry");
for (i=0; i<menu_array.length; i++) {
_global.menu_array[i].label = menu_array[i].attributes.label;
_global.menu_array[i].url = menu_array[i].attributes.url;
}
_root.movie_loading();
};


*******************************************************
MENU.XML FILE
***********
<menu>
<entry label="HOME" url="index.html" />
<entry label="PORTFOLIO" url="index_sub3.html" />
<entry label="ABOUT US" url="index_sub.html" />
<entry label="SOLUTION" url="index_sub4.html" />
<entry label="NEWS" url="index_sub4.html" />
<entry label="CONTACT" url="index_sub2.html" />
</menu>

BLiZZaRD
12-23-2008, 03:49 PM
:D first, when posting code, wrap it in code tags ( [ code] stuff here [ /code] ) makes it easier to read. Second, when code is all over an fla file, we probably need to see the fla file. You can zip it and add it to your post if it is too big to post by itself.

I will try to weed through the code above, but think about attaching the fla. There may be things hidden you haven't seen yet, or in places you wouldn't think to look.

JenJ
12-23-2008, 09:49 PM
I tried posting the .fla first, (.zipped) with the .as and the .xml as well - but it was too big. I'll try again this afternoon when I get back to my main work computer.

Sabao
09-22-2010, 12:56 PM
menu_array[0].url
Does any one knows how to fix this kind of menu or help me in the right direction?
www.lakelandweb.net/lakeland-office-cleaning

Every time I click on the menu tabs it open error no /menu_array[0].url and I dont know were else to look for it to fix and probably I wont know how, Can someone help me?

Thanks, Sabao