PDA

View Full Version : Properties from Array


cnsoneill
12-08-2003, 10:41 PM
I want to load properties from an array. Can I do this?

[_x,_y,_alpha,_visible];
[200,200,100,False];

How can I concatenate the two into code that executues?

Regards,

Chris

cnsoneill
12-08-2003, 10:44 PM
This will also work for me...

ypos = getProperty("_root.btn", _y);

How can I make that _y a variable?

Chris

CyanBlue
12-08-2003, 10:59 PM
Howdy... ;)

I do not quite understand what your question is, but try this code and see if you can use any of it... ;)property_arr = new Array("_x", "_y", "_alpha", "_visible");
value_arr = new Array(200, 200, 50, true);

for (i = 0 ; i < property_arr.length ; i++)
{
_level0.btn[property_arr[i]] = value_arr[i];
}

Stimpson
12-09-2003, 06:16 AM
Juist a variation on CyanBlue idea :),


property_arr = new Array("_x", "_y", "_alpha", "_visible");
value_arr = new Array(200, 200, 50, true);

function setProps(which){
for(var prop in property_arr){
which[property_arr[prop]]=value_arr[prop];
}
}

setProps(this.btn);

Mortimer Jazz
12-11-2003, 07:47 PM
- all you need to do is load the property values from an array and apply them to your objects.

For example say I have an array of values like this:
propVals = new Array(100,200,50, true);

propVals[0] is my x-position and is equal to 100;
propVals[1] is my y-position and is equal to 200;
propVals[2] is my alpha and is equal to 50(%);
propVals[3] is my visibility and is true

So, if I have a movieclip called myMC I can now set it's properties like this:
myMC._x = propVals[0];
myMC._y = propVals[1];
myMC._alpha = propVals[2];
myMC._visible = propVals[3];

If for some reason you wanted the property names to be in one array and the property values to be in another as in your example you could do this (although I see no reason to want to do it):

props = new Array("_x","_y","_alpha","_visibility");
propVals = new Array(100,200,50,true);

myMC[props[0]] = propVals[0];
myMC[props[1]] = propVals[1];
myMC[props[2]] = propVals[2];
myMC[props[3]] = propVals[3];







note: remember that if the visibility is false it may override any alpha value that's been set.

cnsoneill
04-30-2004, 07:39 AM
I am new to arrays... programming in general. I am doing an animation project that involves a great many different characters and camera angles. I have a nice data driven choreography where I create an XML table from access/excel that lists all the chaacter and sub-character states for any given frame (moment). The columns or child nodes list what the moving part is named. The data element then contains the value to set the state. So, in one row... say frame 200... there might be a column heading that says guy.head._xscale. The value would be 20. I am looking to concatonate that two together to end up with a complete instruction. So looking at the above example with MyMC... I want that to be a variable also.

I am sorry I have taken so long to respond. I had to put the project on hold and am now only just starting it up again. I really appreciate all the good ideas from Mortimer, Stimpson, and CyanBlue.

I will be happy to share my project with you guys if you want to see it.

Chris