Log in

View Full Version : how to get an id into a duplicate movieclip



mrtvo
04-05-2008, 05:57 PM
hi there

i've got a small problem,
i'm creating buttons with duplicate movieclip
but when i use a onPress function i can't send my id with it.

Can someone help me please, i'm stuck :(

See my script below



var total = this.aantal_news;
for (i=0; i<total; i++) {
if(old_y==undefined){
old_y=0;
}
duplicateMovieClip(_root.nieuws.txtMC, "txtMC"+i, i);
_root.nieuws["txtMC"+i].news_item.styleSheet = Style;
_root.nieuws["txtMC"+i].news_item.autoSize=true;
_root.nieuws["txtMC"+i].news_item.htmlText = this["message"+i];

trace("***********************")
trace("1: i="+i)
trace("ID:"+this["id"+i])
//HERE i've got my ID
trace("***********************")

_root.nieuws["txtMC"+i].news_item._y = old_y+20
old_y=old_y+_root.nieuws["txtMC"+i].news_item._height;
_root.nieuws.gotoAndPlay(2);



//With this i get my i into my onPress
_root.nieuws["txtMC"+i].i = i;

_root.nieuws["txtMC"+i].onPress = function() {
// NOW HERE IS WHERE I NEED MY ID AGAIN
// but can't get id inhere
_root.nieuws.gotoAndPlay(10);

ItemData1 = new LoadVars();
ItemData1.onLoad = function(){
Style = new TextField.StyleSheet();
Style.load("style.css");
_root.nieuws.news_items1.styleSheet = Style;
_root.nieuws.news_items1.autoSize=true;
_root.nieuws.news_items1.htmlText = this.message;

trace(_global.base_url+"news.php?r=" + random(999)+"&id="+ids)
};
ItemData1.load(_global.base_url+"news.php?r=" + random(999)+"&id="+this[id+this.i]);
}
}

Medyman
04-07-2008, 12:56 PM
I haven't tested your code, but what I usually do in this instance is to use eval() (http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary200.html)


var x:MovieClip = eval("txtMC" + i);
x.id = i;
x.onPress = function() {
trace("I just clicked on txtMC" + this.id);
}