all groups > flash actionscript > october 2005 >
You're in the

flash actionscript

group:

how to convert a variable to an array


how to convert a variable to an array fermer
10/2/2005 9:21:39 PM
flash actionscript:
current code:
for (var i = 0; i < nCount; i++) {// where nCount is determined by
xml.childNodes.length.
var iPlus:Number = i + 1;
var clip1 = createEmptyMovieClip(["clipHolder" + iPlus],
this.getNextHighestDepth());
}
trace(clip1);// returns:
_level0.clipHolder1
_level0.clipHolder2
_level0.clipHolder3
_level0.clipHolder4
_level0.clipHolder5
_level0.clipHolder6
_level0.clipHolder7

can I do something like:

clip1.onRollOver = function(){
clip1.current. the clip directly below._y = somewhereElse;
}
that way I can use currently rolled over clip to move the clip or clips below
it.

I've tried a couple of things with no result.

thanks

fermer
Re: how to convert a variable to an array kglad
10/2/2005 10:07:03 PM
for (var i = 1; i<=nCount; i++) {
// where nCount is determined by xml.childNodes.length.
var clip1 = _root.createEmptyMovieClip(["clipHolder"+i],
this.getNextHighestDepth());
clip1.ivar = i;
clip1.onPress = function() {
for (var j = this.ivar+1; j<=nCount; j++) {
_root["clipHolder"+j]._y += whatever;
}
};
}
Re: how to convert a variable to an array fermer
10/2/2005 11:43:14 PM
Re: how to convert a variable to an array kglad
10/3/2005 12:00:00 AM
Re: how to convert a variable to an array fermer
10/3/2005 12:12:29 AM
Hmmm, that didn't seem to work. I'll attach my code for anyone who wants to
look at this.

var nextMenu:Number = 22;
var cWidth:Number = 170;
var cHeight:Number = 21;
//
function loadXML():Void {
var XMLcall = new XML();
XMLcall.ignoreWhite = true;
XMLcall.load("myDropDownMenuData.xml");
XMLcall.onLoad = function(success) {
if (success) {
buildMenu(this);
}
};
//end XMLcall.onLoad
}
//end loadXML
//
function buildMenu(xml:Object, menu:MovieClip) {
var xnCurrent:XMLNode;
var nCount:Number = xml.firstChild.childNodes.length;
for (var i = 0; i < nCount; i++) {
var iPlus:Number = i + 1;
//xml
xnCurrent = xml.firstChild.childNodes[i];
var xn_Top:String = xnCurrent.childNodes[0].firstChild;
var aLvl2MnuGrp = xnCurrent.childNodes[1].childNodes;
var nLvl2:Number = aLvl2MnuGrp.length;
xnCurrent =
xml.firstChild.childNodes[i].firstChild.nextSibling.firstChild.nodeName;
var childNum = xnCurrent;
xnCurrent = xml.firstChild.childNodes[0].nodeName;
var nmeMnu = xnCurrent;
xnCurrent = xml.firstChild.childNodes[i];
var menuID = xnCurrent.attributes.id;
//clips
var clip2 = this.createEmptyMovieClip(nmeMnu + menuID + "childClipHolder",
this.getNextHighestDepth() * 2);
clip2._y = nextMenu * iPlus;
with (clip2) {
beginFill(0x333333, 100);
moveTo(0, 0);
lineTo(0, cHeight);
lineTo(cWidth, cHeight);
lineTo(cWidth, 0);
lineTo(0, 0);
endFill();
}
var clip1 = this.attachMovie("mcMenuItem", "myMenu",
this.getNextHighestDepth());
trace(clip1);
clip1._y = nextMenu * iPlus;
var myText = clip1.createTextField("myText", this.getNextHighestDepth(), 0,
0, cWidth, cHeight);
clip1.myText.selectable = false;
clip1.myText.html = true;
clip1.myText.htmlText = "<font color='#FFFFFF' face='Verdana' size='10'><b>"
+ xn_Top + "</b></font>";
clip1.onRollOver = function() {
this.myText.textColor = 0xFFCC00;
//clip1.ivar = i;
//for (var j = this.ivar+1; j<=nCount; j++) {
//_root["myMenu"+j]._y = 30;
//}
};
clip1.onRollOut = function() {
this.myText.textColor = 0xFFFFFF;
};
for (var k = 0; j < nLvl2; k++) {
var kPlus = k + 1;
var lvl2Label:String = aLvl2MnuGrp[j].firstChild.nodeValue;
var clip3 = clip2.createEmptyMovieClip(childNum + "tHolder_" + kPlus +
"mc", clip2.getNextHighestDepth());
var childText = clip3.createTextField("myChildText",
clip2.getNextHighestDepth(), 0, 0, cWidth, cHeight);
clip3.myChildText.selectable = false;
clip3.myChildText.html = true;
clip1.myChildText.htmlText = "<font color='#FFFFFF' face='Verdana'
size='10'><b>" + lvl2Label + "</b></font>";
trace("cText" + childText.getDepth());
}
//end nested for loop
}
//end first loop
}
//end buildMenu
//
loadXML();
Re: how to convert a variable to an array kglad
10/3/2005 12:38:23 AM
your code's not going to work because you're trying to define ivar within the
onPress handler which is long after i has reached its last value in the
for-loop. try:

var clip2 = this.createEmptyMovieClip(nmeMnu + menuID + "childClipHolder",
this.getNextHighestDepth() * 2);
clip2._y = nextMenu * iPlus;
with (clip2) {
beginFill(0x333333, 100);
moveTo(0, 0);
lineTo(0, cHeight);
lineTo(cWidth, cHeight);
lineTo(cWidth, 0);
lineTo(0, 0);
endFill();
}
var clip1 = this.attachMovie("mcMenuItem", "myMenu",
this.getNextHighestDepth());
trace(clip1);
clip1.ivar = i;
clip1._y = nextMenu * iPlus;
var myText = clip1.createTextField("myText", this.getNextHighestDepth(), 0,
0, cWidth, cHeight);
clip1.myText.selectable = false;
clip1.myText.html = true;
clip1.myText.htmlText = "<font color='#FFFFFF' face='Verdana' size='10'><b>"
+ xn_Top + "</b></font>";
clip1.onRollOver = function() {
this.myText.textColor = 0xFFCC00;

for (var j = this.ivar+1; j<=nCount; j++) {
_root["myMenu"+j]._y = 30;
}
};

Re: how to convert a variable to an array fermer
10/3/2005 10:49:33 AM
Hmmm I'm not sure if my last post took so if this is a repeat please forgive...

anyway as I was saying: You my friend are a freakin genius...

that worked perfect.

thanks

AddThis Social Bookmark Button