Skip to main content
Participant
November 29, 2006
Question

problem creating dynamic instances of a component

  • November 29, 2006
  • 9 replies
  • 515 views
I have created a component called tab which I'm using in another movie. In the main movie, the linkage identifier for the tab component is called tab. I'm trying to create an empty movie clip and then create a dynamic amount of instances of this tab component and attaching them to the empty movie clip but it's not quite working. It is creating an instance fo the component, but I can't figure out how to set the properties of the component such as it's x coordinate or any of the defined parameters I created when building the component. Here's the script I have... can anyone see why it's not working? Thanks.


function SetupTabs()
{
var tabs = new Array("tab1", "tab2", "tab3", "tab4"); //tmp array
createEmptyMovieClip("container",0);
var prevTB:Object; //used for position - copy of previous tab object

for (i = 0; i < tabs.length; i++)
{
initOb = {BGColor:"0x37527E",FontColor:"0xFFFFFF",Link:"test.htm",LinkTitle:tabs ,OverBGColor:"0x990000",OverTextColor:"0x000000"}; //initObject parameters for tab object
var tb:Object = container.attachMovie("MM_Tab", "tab" + i, i, initOb);
container._x = 65;

if (i > 0)
tb._x = prevTB._x + prevTB.Width; //position current tab to the right of previous tab
else
tb._x = 75;

prevTB = tb;
}
}
This topic has been closed for replies.

9 replies

kglad
Community Expert
Community Expert
November 30, 2006
you're welcome.
Participant
November 30, 2006
I ended up reworking it with a class definition that linked to the component and that took care of everything. Thanks for your help!
kglad
Community Expert
Community Expert
November 30, 2006
cpLeft and cpRight are not instantiated until the 2nd frame of your component and therefore their _width properties are unavailable in the 1st frame. therefore, the Width property of your component is NaN.
kglad
Community Expert
Community Expert
November 29, 2006
go ahead of post a link.
Participant
November 30, 2006
Here's the link. http://os.careermarketplace.com/tmp/tab_menu.zip There are 2 files. cmp_Tab.fla is the actual component file. The mm_menu.fla is the file that is trying to use the component. Let me know if you see what I've done wrong. Thanks!
Participant
November 29, 2006
Sorry, I can see how my answer was misleading. What I should have said was that those properties are defined in the component definition inspector. In the first frame of the component on the actions layer, if the internal variables that the inspector properties reference have not been set, then yes, I do set them to a default value. When I'm back at work tomorrow, I'll zip up the two .flas and post a link if you want to take a look at them. Thanks.
kglad
Community Expert
Community Expert
November 29, 2006
that answer doesn't make sense. those properties must exist either on the main MM_Tab timeline or as part of the class definition of which MM_Tab is a member.

i suspect they do not now exist and that's the problem. create those properties. they can be assigned default values, if you like. the default properties will be over-ridden by your initOb where the properties coincide.
Participant
November 29, 2006
Yes, it does a check to see if they are created and if not, it creates them. And the prevTB.Width is another property I created to keep track of the overall tab width.
kglad
Community Expert
Community Expert
November 29, 2006
does your MM_Tab movieclip have those properties instantiated on the MM_Tab timeline? (and change prevTB.Width to prevTB._width).
kglad
Community Expert
Community Expert
November 29, 2006
what's MM_Tab and what's its relationship to linkage id tab?
Participant
November 29, 2006
I'm sorry. I copied this post from another messageboard where I posted earlier today and only changed the function code but forgot to update the actual message. MM_Tab is the linkage identifier in the component. From all the testing and debugging I've done, it seems that the initObject argument of the attachMovie isn't working correctly. When it displays the movie, my components that it does display are black and the text says undefined.. so it appears that the properties I'm feeding in through the initObject aren't being passed to my component.