Array i thought i knew them, but

Hi all,

In short:
Load an xml doc. and dynamicly create movieclips (that acts as buttons) with the corresponding names. Furthermore the onpress will load the text in an movieclip.

What i have done:
I created 3 arrays to hold the data.
[AS]
var myClipArray = new Array ();
var myClients = new Array ();
var myCases = new Array ();

[/AS]

I created the movieclips as buttons.


//loop thru the xml
count = portfolioTag.childNodes.length;
for (child = 0; child < count; child++) {
//CREATE A MC TO ACT AS MENU BTN
portfolioBtn = _root.createEmptyMovieClip ("mc" + child, child);
portfolioBtn.createTextField ("txt", child + 1, 1, 1, 200, 35);
portfolioBtn.NAME = currentClient.attributes.NAME;
myClients.push (portfolioBtn.NAME);
portfolioBtn.txt.text = portfolioBtn.NAME;
//get the case text and put it in an array
portfolioBtn.TEXT = currentClient.attributes.TEXT;
myCases.push (portfolioBtn.TEXT);
trace ("CASE TEXT: " + myCases[child]);
.....................
........................etc

The as above works

Now the problem:


//here are the actions onPress
//the corresponding case needs to be loaded into mc content
_root["mc" + child].onPress = function () {
	trace (this);
	this.onEnterFrame = function () {
	var thisCase = myCases[child];
	_root.content.scroller.text = thisCase;
			};
		};

somehow i can’t get the corresponding case. I can’t make this


var thisCase = myCases[child];

dynamic.
When i use for example var thisCase = myCases[0]; it gets the text of my first case.

any ideas???

Hi,

I take it that last bit of code is included in the for loop. isn’t it?
And , to tell you the truth, I don’t know why don’t u use the ‘portfolioBtn’ variable as the way to call your button. I would actually, for the sake of clearness, push the created buttons into an array that I would retrieve with a for loop knowing that its index numbers coincide with the cases array.

SHO

yep your right the last code bit is part of the loop.

And yes i have tried/used ‘portfolioBtn’

The thing is i can’t get the “right” var ‘child’ into the onPress function. When i try that, it just gets the latest for every button.

Where do i go wrong???

btw:
i used this to put the btn’s in an array
myClipArray.push (portfolioBtn);
trace(myClipArray[child]);
for (var i = 0; i < myClipArray.length; i++) {
var clip = myClipArray*;
clip.growMe (50, 60 + i * 30, 0.3);
}

Hi,

Don’t see anything wrong in your second post.

In the first post I don’t understand the need of the enterFrame.

I would parse the XML as u do and push any necessary data into its own array (in this case the buttons [and anything else u need])(assuming u’ve declared an array for them first). Then (when I’m sure all the parsing is done) would initialize the buttons
(this.initButts() ; ) :

[AS]
myClass.initButts = function(){
for (var i=0; i<myClipArray.length; i++){
var theButt =myClipArray*;
theButt.myClass = this;
theButt.onPress=function(){
var index = this._name.substring(2);
this.myClass.doWhatever(index);
}
}
}
myClass.doWhatever = function(index){
var thisCase = myCases[index];
_root.content.scroller.text = thisCase;
}
[/AS]
looks like u’re not creating a class in wich case myClass is the root. If the code is part of a class u should protype the function:
myClass.prototype.initButts = function(){

}
myClass.prototype.doWhatever = function(){

}

I have experienced this when I have created movieClips in a for loop and try to assign an onEnterFrame.

When you write
[AS]//here are the actions onPress
//the corresponding case needs to be loaded into mc content
_root[“mc” + child].onPress = function () {
trace (this);
this.onEnterFrame = function () {
var thisCase = myCases[child];
_root.content.scroller.text = thisCase;
};
};[/AS]

It seems like it will work. Now let’s take the first occurrence as an example. You have created a movie clip called mc0. In the onEnterFrame you set thisCase = myCases[child]. At this point child= 0. But when the for loop continues child will increment.

Thus when we reach the limit of the for loop and “finish” with it child will equal count. And so every onEnterFrame will now have in effect this as it’s code
[AS]
this.onEnterFrame = function () {
var thisCase = myCases[count];
_root.content.scroller.text = thisCase;
};
[/AS]

What you need is the value of child at the time of creating the movie clip. What I would do is use the fact that you are using the number to name the movie clip. Try this:
[AS]
this.onEnterFrame = function(){
var thisCase = myCases[this._name.substring(2)];
_root.content.scroller.text = thisCase;
};
[/AS]

If I misuderstood your question you can disregard this message.

B ut I hope it helped.

Ro


var thisCase = myCases[this._name.substring (2)];

Helps a lot, but when testing the movie content.scroller.text only gets update twice???

Sorry got this, by putting


_root.content.scroller.text = thisCase;

out of the onEnterFrame

Furthermore , eki your as with the two classes/prototypes sounds promising gonna try that approach as well