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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function

Status
Not open for further replies.

vulvair

Technical User
Oct 30, 2002
10
GB
Could you please tell em how to create a function for this

MCColor=new Color("menu.bgmenu") ;
MCColor.setRGB(0x9999AA);

I would like the paramters to be the mc the color will be applied to, and the color itself
 
//function with parameters
function newColour(clip, colour) {
MCColor = new Color(clip);
MCColor.setRGB(colour);
}
//call function this way...
newColour(menu.bgmenu, '0x9999AA');
 
Thanks a lot for that, now for the seccond part ;)

I have an array of clips and colours which I want to pass through the function. This is my code so far:

function newColour(clip, colour) {
MCColor = new Color(clip);
MCColor.setRGB(colour);
}
clips = [menu, content, bottom, middle];
colours = [0x9999AA, 0x3333AA, 0x1234cc, 0x1111BB];
for (i=0, j=0; i<3, j<3; i++, j++) {
newColour(i, j);
}

UNfortunately nothing happens, The isntaces are on the main timeline, and this code is executed on frame one of the main timieline.

What should be happening is thta the clips in the array should change to the color listed in the colours array, any idea hopw to help?

Thanks
 
function newColour(clip, colour) {
MCColor = new Color(clip);
MCColor.setRGB(colour);
}
//
clips = [menu, content, bottom, middle];
colours = ['0x9999AA', '0x3333AA', '0x1234cc', '0x1111BB'];
//
for (i=0; i<4; i++) {
newColour(clips, colours);
}
 
Sorry, forgot to put code tags in and the TGML took out the array indices. Here's the code...

Code:
function newColour(clip, colour) {
    MCColor = new Color(clip);
    MCColor.setRGB(colour);
}
//
clips = [menu, content, bottom, middle];
colours = ['0x9999AA', '0x3333AA', '0x1234cc', '0x1111BB'];
//
for (i=0; i<4; i++) {
    newColour(clips[i], colours[i]);
}
 
Actually that doesn't work (nothing happened), I think its because you have to add in the sunction paramters when you call it, like this:

function newColour(clip, colours) {
MCColor = new Color(clip);
MCColor.setRGB(colour);
}
//
clips = [menu, content, bottom, middle];
colours = ['0x009933', '0x3333AA', '0x1234cc', '0x1111BB'];
//
for (i=0; i<4; i++) {
newColour(clips, colours);
}

The problem is that when i do this, it turns all the MCs to black, any idea why?
 
Sorry I should have specified that for the use of this I will need to use 2 arrays, one for colours and one for clips

with this code

function newColour(clip, colour) {
MCColor = new Color(clip);
MCColor.setRGB(colour);
}
//
clip = [menu, content, bottom, middle];
colour = ['0x9999AA', '0x3333AA', '0x1234cc', '0x1111BB'];
//
for (i=0 ,j=0; i<4, j<4; i++,j++) {
newColour(clip, colour[j]);
}

all the clips are set to the same colour...
 
OK It's now working

function newColour(clip, colour) {
MCColor = new Color(clip);
MCColor.setRGB(colour);
}
//
clip = [menu, content, bottom, middle];
colour = ['0x336666', '0xCC9933', '0x1234cc', '0x1111BB'];
//
for (i=0, j=0; i<4, j<4; i++, j++) {
newColour(clip, colour[j]);
}


Thanks so very much for your help.
 
The second version I sent definitely works (the first one was affected by the mark-up language this forum uses which turns a square bracketed 'i' into italics - it happened in your posts too). You don't need two loop counters if you're counting to the same number, just one used as the index for two arrays.
 
Actually for this project I do need two loop counters (though this may not seem obvious why whenyou see this code).

Thanks again for your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top