Object Dynamics

  • Galvitron
  • Newbie
  • Newbie
  • Galvitron
  • Posts: 5

Post 3+ Months Ago

Good Day

Im a C++ Coder working with ActionScript

ill get right to my question:

TestObj = Function(){

this.Data1=0;
this.Data2=0;
}

ok what im looking to do is have a loop like a for loop or something that creates say 100 instances of TestObj

each instance has to have its own name so how can i do that in a loop?

im new to actionscript so forgive my syntax

as well can i pass a whole Object instance into a function

say:

Test1 = new TestObj;
Test2 = new TestObj;

//later

AddData(Test1):


the AddData function(to take an object){

this.Data1 = this.Data1 +2;
this.Data2 = this.Data2 +2;
}


so say i have two big buttons one for Test1 and one for Test2 and when they are pressed it passes the obj as parameter..follow?
so i want the function to be dynamic somehow

i dont know :cry: can any one offer any enlightenment on this area for me

thanks in advance
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • phpSelectah
  • Student
  • Student
  • User avatar
  • Posts: 97

Post 3+ Months Ago

use the eval or set function as :

Code: [ Select ]

  for (i=0;i<15;i++) {
    eval ("obj" + i ) = new obj( 1 , 5 ,7 );
  }
  1.   for (i=0;i<15;i++) {
  2.     eval ("obj" + i ) = new obj( 1 , 5 ,7 );
  3.   }


not the exact code, but the concept will return the desired results.

Hope that helps :D
  • Galvitron
  • Newbie
  • Newbie
  • Galvitron
  • Posts: 5

Post 3+ Months Ago

ok i think i follow you...

your using eval to convert the name of the instance into a value and then assigning that to be the name of the new instance but what is the

1,5,7 all about?
  • phpSelectah
  • Student
  • Student
  • User avatar
  • Posts: 97

Post 3+ Months Ago

Galvitron wrote:
ok i think i follow you...

your using eval to convert the name of the instance into a value and then assigning that to be the name of the new instance but what is the

1,5,7 all about?


just generic arguements, lol
  • Galvitron
  • Newbie
  • Newbie
  • Galvitron
  • Posts: 5

Post 3+ Months Ago

obj = function(){
this.size = 0;
this.statquo = false;
}
for (i=0;i<15;i++) {
eval ("obj" + i ) = new obj();
}
obj5.statquo = true;
trace(obj5.statquo);

when i try this code i get the following error am i doing it right??

Scene=Scene 1, Layer=Layer 1, Frame=1: Line 9: Left side of assignment operator must be variable or property.
eval ("obj" + i ) = new obj();
  • phpSelectah
  • Student
  • Student
  • User avatar
  • Posts: 97

Post 3+ Months Ago

you may need to put the whole assigment into the eval call.


;D
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Galvitron - please use the bbCode button for "code" when you post code on the board. If you perchance forget to turn off HTML when you post it could screw up the appearance of your post or the whole thread. It also helps to make the code stand out from the rest of your post and makes it easier to see. Thanks

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 54 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.