Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.18 / 5.00 3,534 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.80 / 5.00 4,200 ViewsHey guys,
I found I really cool XML based menu online that I want to utilize in a project. My problem is that when I run this all by itself with no scenes, it works perfect. But, when I try to add the menu to my project (which has a preloader scene(1st) and then the main scene(2nd - where the menu is placed) ) it fails to initialize. Here is the code in question:
//designed and developed by www.nogrids.com
//very easy to set up a new menu, just change the values from the xml file
import flash.filters.DropShadowFilter;
import mx.transitions.Tween;
import mx.transitions.easing.*;
stop();
//create function to add buttons
function addButtons() {
pushOverX = 0;
for (i=0; i<obj.buttons.length; i++) {
btn = buttons.attachMovie("menu", "menu"+i, i, {_x:pushOverX, _y:0});
btnsArray.push(btn);
pushOverX += btn._width + btnSpacing;
btn.itemOverColor = obj.buttons[i].attributes.itemRollOverCo lor;
btn.itemColor = obj.buttons[i].attributes.itemColor;
btn.parentBtn.name_txt.text = obj.buttons[i].attributes.title;
btn.parentBtn.name_txt.textColor = btn.itemColor;
//create menuItems array to store the text labels (do not change the array name, keep it >>menuItems<<);
btn.menuItems = new Array();
btn.links = new Array();
for (j=0; j<obj.buttons[i].childNodes.length; j++) {
btn.menuItems.push(obj.buttons[i].childN odes[j].attributes.title);
btn.links.push(obj.buttons[i].childNodes [j].attributes.link);
}
//add shadow filter
btn.filters = [ds];
}
}
var ds:DropShadowFilter = new DropShadowFilter(2, 45, 0x000000, 100, 6, 6, 1.1, 3);
//space between buttons
var btnSpacing:Number = new Number();
//object that contains data from xml
var obj:Object = new Object();
//create nex xml object
var xml:XML = new XML();
xml.ignoreWhite = true;
//after the xml is loaded, load variables and parse the date to obj
xml.onLoad = function(succes) {
if (succes) {
//bS = Number(this.firstChild.attributes.spacin g);
obj.buttons = this.firstChild.childNodes;
btnSpacing = Number(this.firstChild.attributes.button sSpacing);
//function call
addButtons();
} else {
trace("xml could not load");
}
};
//the path to the xml file
xml.load("menu.xml");
//this part is for tooltip functionality, if you don't need a tooltip you can delete the code
var mouseListener:Object = new Object();
var btnsArray:Array = new Array();
var showMenu:Boolean = true;
_global.showTooltip = true;
function hideAll() {
for (i=0; i<btnsArray.length; i++) {
mc = btnsArray[i];
mc.enabled = false;
}
buttons.tweenAlpha.stop();
buttons.tweenAlpha = new Tween(buttons, "_alpha", Strong.easeOut, buttons._alpha, 0, 2, true);
}
function showAll() {
for (i=0; i<btnsArray.length; i++) {
mc = btnsArray[i];
mc.enabled = true;
}
buttons.tweenAlpha.stop();
buttons.tweenAlpha = new Tween(buttons, "_alpha", Strong.easeIn, buttons._alpha, 100, 2, true);
}
Mouse.addListener(mouseListener);
mouseListener.onMouseDown = function() {
if (_global.showTooltip) {
if (showMenu) {
showMenu = false;
tooltip.txt.text = "+ Click to show menu";
hideAll();
} else {
showMenu = true;
tooltip.txt.text = "- Click to hide menu";
showAll();
}
}
};
tooltip.txt.text = "- Click to hide menu";
tooltip.onEnterFrame = function() {
//follow the cursor
if (_global.showTooltip) {
this._visible = true;
this._x = _xmouse+10;
this._y = _ymouse+5;
updateAfterEvent();
} else {
//if a menu is active hide the tooltip
this._visible = false;
}
};
If you guys want to see the XML, let me know. I know this has to be a simple fix, I appreciate any help that comes my way.
-Human
Simple fix: Don't use scenes.
Can't you just put you work on two different frames of the same scene?
.
At 10/17/08 05:14 AM, Fion wrote: Simple fix: Don't use scenes.
Can't you just put you work on two different frames of the same scene?
A very simple fix indeed. I moved my preloader over to the main scene and everything is working perfectly. I guess the whole scenes thing in Flash is pretty much pointless. So, I learned my lesson.. thanks for the tip Fion.
-Human
Another question..
Any idea on how I would add gotoandStop functionality to the code pasted above? I would like to be able to edit the XML file to tell the SWF to gotoandStop on a specified frame on the main timeline. I have already tried a few things and I can't seem to get it to work.
-Human
Bump..
Have any of you guys tried doing a gotoandStop frame through XML?
-Human