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

flash actionscript

group:

attachmovieclip issue


attachmovieclip issue vusubhashini
12/29/2005 10:37:42 PM
flash actionscript:
When I do the attach movieclip...its not working...can u pls check it out?

just teach me step by step...how do i add a movie clip in a loop..?


rightmenu_mc = is name of movie clip and name of instance of the movie clip
what are the values to be inserted in the attachmovie(instance name, new name,
how many?)

Am I right?

var item_count=0;
var item_spacing = 28;
for (m=0;m<subItemNode.length;m++)
{
var subItem_mc =
rightmenu_item.attachMovie("rightmenu_mc","subitem"+item_count, item_count);
trace("subItem_mc :"+subItem_mc);
subItem_mc._y = item_count * item_spacing;
item_count++;
}

Re: attachmovieclip issue dr_ross
12/29/2005 10:42:37 PM
Theres always the flash help there to get a reference from. In this case the
thrid parameter of attachMovie is not how many but the depth on which to place
the movie clip. Only one movieclip can occupy one depth at a time, the higher
the depths appear above lower depth movieclips.
You'll aslo need to check you have the runtime linkage set on the movieclip
your trying to load. So right like on it in the library and check the
Properties -> export for actionscipt.

Theres plenty of examples of this in the flash help, and the reference for
methods like attachMovie as well for anything you're unsure of

Hope that helped, dr_ross
Re: attachmovieclip issue vusubhashini
12/30/2005 3:51:36 PM
Thanks Ross,

[AS]function loadXML(_f)
{
var navigation_xml = new XML();
navigation_xml.ignoreWhite = true;
navigation_xml.onLoad = function(success){
if (success){CreateMenu(this);}
else trace("Error loading XML file");
}
navigation_xml.load(_f);
}
loadXML("../deploy/autos_manufacturer.xml");

function CreateMenu(xmllist){
items = xmllist.firstChild.childNodes[0].childNodes;
var itemsArray;
var item_count=0;
var item_spacing = 3;
trace("items.length"+items.length);
for (i=0;i<items.length;i++)
{
mainItem_mc =
_level0.nav_mc.mainmenu_item.attachMovie("mainmenu_mc","mainItem"+item_count,{_y
:50*i});
mainItem_mc._y = item_count + item_spacing;
trace("mainitem._y :"+mainItem_mc._y);
item_count++;
trace("item_count :"+item_count);
mainItem_mc.mainmenu_txt = items.attributes.name;
trace("mainItem_mc.mainmenu_txt :"+mainItem_mc.mainmenu_txt);
}
}
[AS]

Everything works...thanks for the reply...but only one issue...the
items.length is 47, but it creates only 2 movieclips, (one for first item and
one for last)...Is there anything wrong in my code?
Re: attachmovieclip issue dr_ross
12/30/2005 6:57:24 PM
The third parameter should be the depth number not the initObject. So replace
it with _root.getNextHighestDepth() or a incrementing variable. Strange how the
compiler didn't pick that up though. Thats more than likely the reason you're
only seeing two mc's as they are overrighting each others depths.

The section where you're applying text to the field seems a bit funky as well.
I'm assuming mainmenu_txt is the name of the text field inside this movieclip
you're attachinng. In which case you need to reference the text property of it
with mainmenu_txt.text to change the text. And it probably won't add anything
anyway as items.attributes.name will probably need to be items.attributes.name
as items in your array of data. Other than that you could refine it a bit but
it looks pretty solid.
AddThis Social Bookmark Button