Jump to content
Search Community

non existing objects and tween :P

blase test
Moderator Tag

Recommended Posts

if i have a multidimensional array with different lenghts, for example:

 

var mArr:Array = [m0,m1,m2,m3];
var pArr:Array = [p0,p1,p2,p3,p4];
var dArr:Array = [d0,d1,d2];

var mainArr:Array = [mArr, pArr, dArr];

 

and if i write a double loop to tween them all (because i want to tween all instances at the same index at the same time), i will ofcourse get an error, null object reference:

 

for(var i:int = 0; i < mainArr.length; i++){;
for(var j:int = 0; j < mainArr[i].length; j++){;
	TweenLite.to(mainArr[i][j], time, {alpha:0, delay:j * 0.1});
}
}

 

is there a way to pull this out?

Link to comment
Share on other sites

  • 3 weeks later...
I don't see why you'd get a null object error with that code. Granted, I haven't tested it myself (very short on time at the moment), but in theory it looks okay to me (although it's not exactly optimized for performance, but it's not the end of the world).

 

How would it look like it it were optimised better? (passing through multidimensional array)

 

Thanks!

Link to comment
Share on other sites

Reduce the array lookups every time through the loops by storing stuff in local variables:

 

var a1Length:uint = mainArr.length;
var nestedArray:Array;
var nestedLength:uint;
var j:uint, i:uint;
for(i = 0; i    nestedArray = mainArr[i];
  nestedLength = nestedArray.length;
  for(j = 0; j       TweenLite.to(nestedArray[j], time, {alpha:0, delay:j * 0.1});
  }
}

 

On large arrays, this can make a big difference.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...