PDA

View Full Version : loops and methods



brndn
December 5th, 2008, 08:07 PM
hi there
I have created a package to handle some 3d bits using papervision.
I am having the issue whereby I have a few static methods that control the planes and bitmapMaterial.

In a nut shell using static methods dont allow the 3d motions to be assigned individually.


Code:
function callThumbs():void {
for (var i:Number = 0; i < my_total; i++) {

var thumb_url = my_images[i].@THUMB;

var coneBlackMaterial:BitmapFileMaterial = new BitmapFileMaterial(thumb_url);
coneBlack = new Plane( coneBlackMaterial, 250, 200, 3, 3);
rootNode.addChild(coneBlack);
Tweener.addTween(coneBlack, { rotationX:0, rotationY:0, z:70, time:1, transition:"easeinoutexpo"});
}
}
basically could some one show me how to create
coneBlack+i = new Plane( coneBlackMaterial, 250, 200, 3, 3);

this is tricky as coneBlack1 needs to be private var cone1: Plane; but i am using a good lot of xml to cycle through the loop, and would like to create the private methods in a loop???

does any one know if this is possible.


thanks

Xannax
December 6th, 2008, 07:19 PM
do you mean this?


var conesArray:Array = new Array();
for(i;i<smthing;i++){
coneBlack = new Plane( coneBlackMaterial, 250, 200, 3, 3);
conesArray.push(coneBlack)
Tweener.addTween(conesArray[i],...
}

then you access it with conesArray[x].prop
Not sure I understand the question though. I particularly don't get what "coneBlack1 needs to be private var cone1: Plane" means.
Aso, leave the material creation outside the loop if it's not gonna change, instantiate it only once and use it in the loop.

brndn
December 8th, 2008, 11:58 AM
kind of.
but the tweener applies to all the items in cone array. so am thinking it has something to do with the use of a single object:
coneBlack = new Plane


if I could create may instances of this object inside the loop it would may work.

if that makes sense

Xannax
December 9th, 2008, 08:07 AM
I am really sorry; I have trouble understanding exactly what you want.
Can you explain more? I'll tell you what I understood, correct me if I am wrong:
1) you want to generate several instances of the "Plane" class
2) you want to apply the coneBlackMaterial to each one of them
3) you want to display all of the planes
4) you want to rotate only one of them
The tweener is applying to all the items in the cone array because it is in the loop; it's an expected behavior.
If you want to apply it only to a particular object, get it out of the loop:

var conesArray:Array = new Array();
for (var i:Number = 0; i < my_total; i++) {
var thumb_url = my_images[i].@THUMB;
var coneBlackMaterial:BitmapFileMaterial = new BitmapFileMaterial(thumb_url);
coneBlack = new Plane(coneBlackMaterial, 250, 200, 3, 3);
conesArray.push(coneBlack)
}
Tweener.addTween(conesArray[x],...

where "x" is the index of the instance you want to apply the tween to (0 is the first, no 1).


it has something to do with the use of a single object

You are creating a new object each time you do coneBlack = new Plane. It's not a single object.
Sorry if all of this is irrelevant. I'm doing my best to understand but sometimes I'm dumb :)

brndn
December 9th, 2008, 07:52 PM
yeh you hit the nail on the head with that answer.

so i guess i have to avoid looping it in this instance.

unless there is a friendlier loop/oject approach

Xannax
December 10th, 2008, 11:29 AM
Maybe if you explain what is the end result you expect, I can help more

brndn
December 10th, 2008, 12:34 PM
sorry thought it made sense.
basically I want each tween to be initiated after the other.
at present two images tween after each other, and the rest dont. so if i am loading 60 images I would like each to tween with in its own time interval. if that makes sense.

Xannax
December 11th, 2008, 11:35 PM
Yea it does. And it's doable. You have to implement some kind of delay before the tween that increments with each loop
The logic is:

var delay:int = new int(0)
var interval:Number = new Number(10)
for(var i:int=0;i<something;i++){
delay = interval * i
}

Then you can delay your tweens according to that interval. The basic Tween class of AS3 doesn't provide a delay property, but from the name of your tween I guess you are using Tweener. It's been a while since I used it, but I'm pretty sure you can set a delay. There must be some kind of {delay} property.
try this:

var conesArray:Array = new Array();
var delay:int = new int(0)
var interval:Number = new Number(10)
for (var i:Number = 0; i < my_total; i++) {
delay = interval * i
var thumb_url = my_images[i].@THUMB;
var coneBlackMaterial:BitmapFileMaterial = new BitmapFileMaterial(thumb_url);
coneBlack = new Plane(coneBlackMaterial, 250, 200, 3, 3);
conesArray.push(coneBlack)
Tweener.addTween(coneBlack, { rotationX:0, rotationY:0, z:70, time:1, transition:"easeinoutexpo",delay:delay});
}


Should work.

brndn
December 12th, 2008, 11:31 AM
awsome champ
time:1
just used var Delay:2+i

time:Delay, inside the tween method.

gracias

Xannax
December 12th, 2008, 01:40 PM
You're welcome, glad to know it finally worked. Good continuation!