Arrays/Objects/Strings

Hi, how can i have an array of strings but also with mc identifiers in the same array and have it know the difference between object and string?

RIght now i’ve got this array of strings that goes to a textfield, and if i change it to

[AS]

portfolioSection([“section 01”, “section 02”, {linkage: “linkage_id”, x: 530, y: 280}, “section 04”, “section 05”]);

this.attachMovie(portfolioSection[2].linkage)[/AS]

to try and attach an MC instead of text in a textfield i just get [object object] in the text field.

I’m not quite sure what you’re trying to accomplish, but you need 3 or 4 parameters for attachMovie:

myMovieClip.attachMovie(idName, newName, depth [, initObject] )

What text field are you talking about that gets [object object]?

It’d help a lot if you posted you .fla file so we can see what you’re doing in more detail.

How can you possibly load a movieclip inside a textfield? :h:

You’re not loading an MC into a textfield. Look at this fla. Click forward three times in the swf to see the [object Object]. I’m exporting the MC linkage_id as actionscript.

That’s because you have this line

[AS]
section_txt.text = aSectionTxt[iSectionIndex]
[/AS]

in your setSectionText routine.

When you get to section 3, the third element in aSectionTxt isn’t a String. It’s an object with three properties: linkage, x and y.

A workaround could be to test the type of the current element like this:

[AS]
if (typeof aSectionTxt[iSectionIndex] == “string”) {
section_txt.text = aSectionTxt[iSectionIndex];
}
else {
section_txt.text = aSectionTxt[iSectionIndex].linkage;
}
[/AS]

That’ll test if the element is a string or not. If it’s a string it takes the element and puts it into section_txt. If it isn’t a string it assumes that it’s an object with a ‘linkage’ property and assigns that instead.

Hope that helps.

So how would that look in this part?

[AS]
setSectionText = function (dir) {
if (dir != undefined) {
iSectionIndex += dir;
}
section_txt.text = aSectionTxt[iSectionIndex];
};
[/AS]

like this?
[AS]
setSectionText = function (dir) {
if (dir != undefined) {
iSectionIndex += dir;
}
if (typeof aSectionTxt[iSectionIndex] == “string”) {
section_txt.text = aSectionTxt[iSectionIndex];
}
else {
section_txt.text = aSectionTxt[iSectionIndex].linkage;
}
[/AS]

That’s the part I was talking about. So yes, that’s how it would look…