Skip to main content
Participant
October 8, 2008
Answered

Problem with duplicate movieclip loop

  • October 8, 2008
  • 3 replies
  • 360 views
Hello, this is more a programming logic problem than actually a problem with the code.

I am building a calendar where each month is built on the fly with duplicate movieclip for each day (with an empty textfield). I build the calendar according to how many days the month has, which day of the week it starts, etc, etc.

Then I load an external xml with news items. Afterwards, I need to check which days of this month have news items. At the moment i have 2 items in my xml feed ( http://s50699.gridserver.com/xml/news_en.xml). This all works fine.

However, I am only managing to highlight one day of that month — the last news item—, meaning that the loop is running twice, but it only records the last number, so the highlighted day that shows on the calendar, is, correspondingly, of that last news item.

I am enclosing the code below, and will be really appreciative of any help or general guidance.
This topic has been closed for replies.
Correct answer kglad
_root["dot"+s] doesn't know it has any relationship to the number i after your for-loop advances. in particular, when _root["dot"+s] is released i will be the last value of your for-loop.

to remedy, use a variable that store the value of i when _root["dot"+s] is created:

_root["dot"+s].ivar = i;

and use this.ivar instead of i in your onRelease handler.

3 replies

kglad
Community Expert
Community Expert
October 11, 2008
you're welcome.
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
October 9, 2008
_root["dot"+s] doesn't know it has any relationship to the number i after your for-loop advances. in particular, when _root["dot"+s] is released i will be the last value of your for-loop.

to remedy, use a variable that store the value of i when _root["dot"+s] is created:

_root["dot"+s].ivar = i;

and use this.ivar instead of i in your onRelease handler.
Participant
October 10, 2008
Thanks for the contribution, klad. I've tried that now, with different variations, and came back to your tip.

I wasted some time because initially i didn't record this new ivar INSIDE the if clause where i checked which day corresponded to a news item. Consequently, the number i got was always the last one (which counts the number of news items in the xml).

A day later, and a night well-slept, it came to me.

Thanks again, you're the man!
kglad
Community Expert
Community Expert
October 8, 2008
you're more likely to receive help if you pinpoint the location of the problem code.
Participant
October 9, 2008
That's fair enough, Kglad... I've detected that the problem was within the makecalendar() function, because I was trying to distinguish which days had news items at the same time i was duplicating the day movieclips. This was solved by doing that job within the xml loading function descodificanews.

Now my problem lies in the process of reading the news content corresponding to any highlighted day. I can detect the movieclip instance I'm clicking on, but i can't match it to the corresponding day...

I'm trying to do this where I've commented "news button control", inside the "descodificanews" function.. Many thanks in advance.