Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shrinking my actionscript code... (with _level0[myvar])

Status
Not open for further replies.

Roel018

Programmer
Jun 12, 2002
30
NL
Dear folks,

Currently I have this peace of code, which works great. However, as you can probably see for yourselves, this isn't the I would like my code to be. I would prefer just ONE "for (var i:Number = 1; i<=Number_of_pictures; i++)" loop so that I need to enter the values below only once.. I know I need to use _level0[variable / mc] but there is one thing I can't do or don't know how to do it: I can point to a dynamic MC name with _level0[mymc] but I can't point to a dynamic variable name like _level0[current_title_of_current_picture]....

Here's the code that works for me: I hope someone can show me how to shrink it:


=======================================================

var TempCount:Number = 0;

if (number_of_pictures >= 1){
TempCount += 1;
currentClip = "picnr" + TempCount;
_level0[currentClip].titleText = _root.picture_1_Title;
tempTitle = _root.picture_1_Title;
url = _root.picture_1_Filename;
size = _root.picture_1_Size;
LoadProgress(currentClip, url, size)
countTitleCharacters(tempTitle)
_root.picnr1.titletextfield.text = newTitleString;
}

if (number_of_pictures >= 2){
TempCount += 1;
currentClip = "picnr" + TempCount;
_level0[currentClip].titleText = _root.picture_2_Title;
tempTitle = _root.picture_2_Title;
url = _root.picture_2_Filename;
size = _root.picture_2_Size;
LoadProgress(currentClip, url, size)
countTitleCharacters(tempTitle)
_root.picnr2.titletextfield.text = newTitleString;
}

if (number_of_pictures >= 3){
TempCount += 1;
currentClip = "picnr" + TempCount;
_level0[currentClip].titleText = _root.picture_3_Title;
tempTitle = _root.picture_3_Title;
url = _root.picture_3_Filename;
size = _root.picture_3_Size;
LoadProgress(currentClip, url, size)
countTitleCharacters(tempTitle)
_root.picnr3.titletextfield.text = newTitleString;
}

if (number_of_pictures >= 4){
TempCount += 1;
currentClip = "picnr" + TempCount;
_level0[currentClip].titleText = _root.picture_4_Title;
tempTitle = _root.picture_4_Title;
url = _root.picture_4_Filename;
size = _root.picture_4_Size;
LoadProgress(currentClip, url, size)
countTitleCharacters(tempTitle)
_root.picnr4.titletextfield.text = newTitleString;
}

if (number_of_pictures >= 5){
TempCount += 1;
currentClip = "picnr" + TempCount;
_level0[currentClip].titleText = _root.picture_5_Title;
tempTitle = _root.picture_5_Title;
url = _root.picture_5_Filename;
size = _root.picture_5_Size;
LoadProgress(currentClip, url, size)
countTitleCharacters(tempTitle)
_root.picnr5.titletextfield.text = newTitleString;
}

if (number_of_pictures >= 6){
TempCount += 1;
currentClip = "picnr" + TempCount;
_level0[currentClip].titleText = _root.picture_6_Title;
tempTitle = _root.picture_6_Title;
url = _root.picture_6_Filename;
size = _root.picture_6_Size;
LoadProgress(currentClip, url, size)
countTitleCharacters(tempTitle)
_root.picnr6.titletextfield.text = newTitleString;
}

=======================================================


I get picture_1-6_Title, picture_1-6_Filename and picture_1-6_Size variables from a database and are allready know in this example..
I need to expand the number of pictures so the above example code would be impossible to maintain since it would grow and grow with every new picture added...

Thnx many times !!!!!!!!!

Greetings
Roel
:confused:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top