PDA

View Full Version : How to produce OO code from this?


kildre
07-19-2002, 04:30 PM
Below is some code I did to make dynamic images change across, what I need to know is it possible to make a loop to create a variable to hold an item within an array?


Like if I have 5 items called "product" and I wanted to make vars of products 1 - 5 like product1, product2, product3 etc. would this then work to call back out?

for (x=0; x<=5; x++;){
Array[outside]="product"+array[x];
}



so if I wanted to assign product3 = 6 persay it would be

Array[2]=6;

or can I call it directly product3= 6?


See below what I am trying to make that gunk below into one object I can load dynamically.



Code snippet........................................... ....





var hope = flashVars.portObject[0].hope;
var plan = flashVars.portObject[0].plan;


pill1Top._alpha=60;
pill1Top._y = (boundBox._y + ((boundBox._height/2)+(pill1Top._height/2))) - (((hope/topVal)*boundBox._height));
pill1Bottom._alpha=60;
pill1Bottom._y=(boundBox._y + ((boundBox._height/2)-(pill1Bottom._height/2))) - ((plan/bottomVal));
pill1Middle._alpha=60;
//trace(pill1Bottom._y - pill1Bottom._height);
pill1Middle._height = ((pill1Bottom._y - pill1Bottom._height/2)-(pill1Top._y+pill1Top._height/2))+1;
//trace(pill1Middle._height);
pill1Middle._y=(pill1Top._y)+(pill1Top._height/2)+(pill1Middle._height/2)-.3;
var expect = flashVars.portObject[0].expect;
pill1Expect._y = (boundBox._y + boundBox._height/2 + (pill1Expect._height/2)) - (((expect/topVal)* boundBox._height) - pill1Top._height);

//boundBox._y + ((boundBox._height/2)+(pill1Expect._height/2))) - (((expect/topVal)*boundBox._height));


/* Pill two -----------------------------------------------*/

var hope = flashVars.portObject[5].hope;
var plan = flashVars.portObject[5].plan;
pill2Top._alpha=60;
pill2Top._y = (boundBox._y + ((boundBox._height/2)+(pill2Top._height/2))) - (((hope/topVal)*boundBox._height));
pill2Bottom._alpha=60;
pill2Bottom._y=(boundBox._y + ((boundBox._height/2)-(pill2Bottom._height/2))) - ((plan/bottomVal));
pill2Middle._alpha=60;
//trace(pill2Bottom._y - pill2Bottom._height);
pill2Middle._height = ((pill2Bottom._y - pill2Bottom._height/2)-(pill2Top._y+pill2Top._height/2))+1;
//trace(pill2Middle._height);
pill2Middle._y=(pill2Top._y)+(pill2Top._height/2)+(pill2Middle._height/2)-.3;
var expect = flashVars.portObject[5].expect;
pill2Expect._y = (boundBox._y + boundBox._height/2 + (pill2Expect._height/2)) - (((expect/topVal)* boundBox._height) - pill2Top._height);


/* Pill three --------------------------------------------------*/


var hope = flashVars.portObject[10].hope;
var plan = flashVars.portObject[10].plan;
pill3Top._alpha=60;
pill3Top._y = (boundBox._y + ((boundBox._height/2)+(pill3Top._height/2))) - (((hope/topVal)*boundBox._height));
pill3Bottom._alpha=60;
pill3Bottom._y=(boundBox._y + ((boundBox._height/2)-(pill3Bottom._height/2))) - ((plan/bottomVal));
pill3Middle._alpha=60;
//trace(pill3Bottom._y - pill3Bottom._height);
pill3Middle._height = ((pill3Bottom._y - pill3Bottom._height/2)-(pill3Top._y+pill3Top._height/2))+1;
//trace(pill3Middle._height);
pill3Middle._y=(pill3Top._y)+(pill3Top._height/2)+(pill3Middle._height/2)-.3;
var expect = flashVars.portObject[10].expect;
pill3Expect._y = (boundBox._y + boundBox._height/2 + (pill3Expect._height/2)) - (((expect/topVal)* boundBox._height) - pill3Top._height);


/* Pill four ------------------------------------------------------*/

var hope = flashVars.portObject[19].hope;
var plan = flashVars.portObject[19].plan;
pill4Top._alpha=60;
pill4Top._y = (boundBox._y + ((boundBox._height/2)+(pill4Top._height/2))) - (((hope/topVal)*boundBox._height));
pill4Bottom._alpha=60;
pill4Bottom._y=(boundBox._y + ((boundBox._height/2)-(pill4Bottom._height/2))) - ((plan/bottomVal));
pill4Middle._alpha=60;
//trace(pill4Bottom._y - pill4Bottom._height);
pill4Middle._height = ((pill4Bottom._y - pill4Bottom._height/2)-(pill4Top._y+pill4Top._height/2))+1;
//trace(pill4Middle._height);
pill4Middle._y=(pill4Top._y)+(pill4Top._height/2)+(pill4Middle._height/2)-.3;
var expect = flashVars.portObject[19].expect;
pill4Expect._y = (boundBox._y + boundBox._height/2 + (pill4Expect._height/2)) - (((expect/topVal)* boundBox._height) - pill4Top._height);


/* Pill five ---------------------------------------------------------*/


var hope = flashVars.portObject[20].hope;
var plan = flashVars.portObject[20].plan;
pill5Top._alpha=60;
pill5Top._y = (boundBox._y + ((boundBox._height/2)+(pill5Top._height/2))) - (((hope/topVal)*boundBox._height));
pill5Bottom._alpha=60;
pill5Bottom._y=(boundBox._y + ((boundBox._height/2)-(pill5Bottom._height/2))) - ((plan/bottomVal));
pill5Middle._alpha=60;
//trace(pill5Bottom._y - pill5Bottom._height);
pill5Middle._height = ((pill5Bottom._y - pill5Bottom._height/2)-(pill5Top._y+pill5Top._height/2))+1;
//trace(pill5Middle._height);
pill5Middle._y=(pill5Top._y)+(pill5Top._height/2)+(pill5Middle._height/2)-.3;
var expect = flashVars.portObject[20].expect;
pill5Expect._y = (boundBox._y + boundBox._height/2 + (pill5Expect._height/2)) - (((expect/topVal)* boundBox._height) - pill5Top._height);
trace("Hope : "+hope);
trace("expect : "+expect);
trace("plan : "+plan);
trace("top : "+topVal);
trace("bottom : "+bottomVal);













Thanks,


Kildre:confused:

Ricod
07-19-2002, 04:40 PM
for (i=1; i<=5; i++;){
_root["product"+i] = i;
}

This way you'll get 5 variables named produkt1, produkt2 etc. which'll reside on the _root.

If u created a new array u can assign the values directly. Take a look in the tutorial section and read up on arrays for questions like this.

kildre
07-19-2002, 08:36 PM
var hope = flashVars.portObject[0].hope;
var plan = flashVars.portObject[0].plan;

for (i=1; i<=5; i++){

_alpha["pill"+i+"Top"] = Top;
_alpha["pill"+i+"Bottom"] = Btm;
_alpha["pill"+i+"Middle"] = Mid;


_y["pill"+i+"Top"] = yTop;
_y["pill"+i+"Middle"] = yMid;
_y["pill"+i+"Bottom"] = yBtm;

_y["pill"+i+"Expect"] = yExp;

_height["pill"+i+"Bottom"] = hBtm;
_height["pill"+i+"Top"] = hTop;
_height["pill"+i+"Middle"] = hMid;
_height["pill"+i+"Exspect"] = hExp;
//Dynamic Alpha settings of top bottom and middle


yTop = (boundBox._y + ((boundBox._height/2)+(hTop/2))) - (((hope/topVal)*boundBox._height));
Top=60;
trace("yTop= "+yTop);

yBtm = (boundBox._y + ((boundBox._height/2)-(hBtm/2))) - ((plan/bottomVal));
Btm=60;

hMid = ((yBtm - hBtm/2)-(yTop+hTop/2))+1;
Mid=60;

yMid=(yTop)+(hTop/2)+(hMid/2)-.3;
var expect = flashVars.portObject[10].expect;
yExp = (boundBox._y + boundBox._height/2 + (hExp/2)) - (((expect/topVal)* boundBox._height) - hTop);
}




This is what I did in return but it doesn't seem to work.. any suggestions?

Ricod
07-23-2002, 01:45 PM
Its a bit hard to filter from all that code u gave ... exactly what IS working properly and which parts aren't ? Or at least : what do u want this code to do, and what is it actually doing ?

Also : _alpha["pill"+i+"Top"] = Top;
I've never seen it like this, but that doesn't mean it isn't correct, just that I've never seen it like this ... can someone confirm this ?

U're refering to _alpha.pill5Top = Top ? for instance ?

pinkaboo
07-23-2002, 02:07 PM
hiya Rico Hon :)

C'mon people! Work those tags! Format that code!

[ as] [ /as] (without the spaces)

I wanna see you lookin' trim you hear me?

;)

Ricod
07-23-2002, 02:22 PM
Hey there bunny ! I'll try ... but only for u, my peach pit !

kildre
07-23-2002, 04:28 PM
If you want I can put up the source code to possibly show you what I am trying to do.

But to answer the short question yes I would like to concatnate the values so you would get

_alpha. .pill5Top = Top;


Thanks.

Ricod
07-23-2002, 05:46 PM
Need more info ... input ... :)

What IS it doing ? And what is it SUPPOSED to do ? :confused:

kildre
07-23-2002, 07:52 PM
Its writing out the variable correctly.. but it isnt making the dynamic variable alpha = 50


I have attached the code ...


Basically Im reading from an external XML file to populate some variables then creates these pill images based of percentages. I want the pills all to show as 50% alpha then when I click on them to be lit up.

The lines will show the average in the middle of the high and low numbers I read in.

My icq is 7108590 if you need further info to help solve this...

kildre
07-23-2002, 11:36 PM
Ok here is the nutshell version


I need to build some dynamic code that will take five instances of a button and set their alpha to 60.



The buttons are comprised of 3 sections a top - middle - bottom

I want to create the code so that the top, mid, btm are all set at same time to alpha 60


so 1 button is like so..


pill1Top._alpha =60;

pill1mid._alpha =60;

pill1btm._alpha =60;


but instead of setting all of the values of all 5 buttons like so..

I wanted dynamic code

like so
for(var i=1; i<=5; i++){
var Top="pill".concat(i)+"Top";
_root.Top._alpha=60;

var Mid="pill".concat(i)+"Mid";
_root.Mid._alpha=60;

var Btm="pill".concat(i)+"Btm";
_root.Top._alpha=60;

}


to get the results of
pill1Top._alpha =60;

pill1mid._alpha =60;

pill1btm._alpha =60;



pill2Top._alpha =60;

pill2mid._alpha =60;

pill2btm._alpha =60;



pill3Top._alpha =60;

pill3mid._alpha =60;

pill3btm._alpha =60;



pill4Top._alpha =60;

pill4mid._alpha =60;

pill4btm._alpha =60;




pill5Top._alpha =60;

pill5mid._alpha =60;

pill5btm._alpha =60;

pinkaboo
07-24-2002, 09:04 AM
okay, try this:


for(var i=1; i<=5; i++){
var Top=_level0["pill" +i+"Top"];
Top._alpha=60;

var Mid=_level0["pill" +i+"Mid"];
Mid._alpha=60;

var Btm=_level0["pill"+i+"Btm"];
Btm._alpha=60;

}


and LOOK!! I used the formatting tags - oohhh! Makes it pretty.

pinkaboo
07-24-2002, 09:08 AM
and if you want to stick with your .concat this should also do the trick:


for(var i=1; i<=5; i++){
var Top="pill".concat(i)+"Top";
_root[Top]._alpha=60;

var Mid="pill".concat(i)+"Mid";
_root[Mid]._alpha=60;

var Btm="pill".concat(i)+"Btm";
_root[Btm]._alpha=60;

}


pinK

Ricod
07-24-2002, 09:48 AM
Its moments like this I know exactly why we married pinKy ;)

kildre
07-24-2002, 02:24 PM
Isnt is funny how something simple can brighten your day like the color Pink?



:D




Thanks!