LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 




 
 
Thread Tools Display Modes
  #1  
Old 03-07-2003, 08:08 PM
dear_stephen dear_stephen is offline
Registered User
 
Join Date: Mar 2003
Location: Germany
Posts: 1
Rep Power: 0
dear_stephen is on a distinguished road
Angry Dynamic object property name creation

I have a real tester for you flash gurus out there. Or at least, I hope so and its not just a bug in Flash.

My problem is that in the code below which is a symplified version of what I am trying to do is that the property (x) is not created when the object obj is local. It works when if is global but I can't have that since I am using a recursibe routine.

I would really appreciate it if someone could give me a tip on this one.

Thanks a million in advance.

Stephen




function rec(x,level){
var obj = new Object();
obj.value=x;
varname="obj."+x;
set(varname,new Array());
if(x<5){
eval(varname)[0]=rec(x+1,level+1);
}else{
return eval(varname);
}
}


trace(rec(1,1));
  #2  
Old 03-08-2003, 12:48 AM
Timothee's Avatar
Timothee Timothee is offline

AS Coderator
 
Join Date: Mar 2002
Location: Singapore
Posts: 664
Rep Power: 12
Timothee is on a distinguished road
Hi dear_stephen,

Welcome to FlashMove !!

To be honnest I can't understand what you are trying to do. What I can say is that if you need to refer to a common object in all the recursive calls, you can either make it global as you mentionned or pass it as a parameter at each call, but you have to be careful if each call modify your object. Recursion is difficult to debug.

Please provide more information. If the original stuff you are doing is not too big, consider posting entirely.

Tim.
__________________
n=4102746880;s="";do{s=String.fromCharCode((n&15)+ 101)+s}while(n>>>=4);trace(s);
  #3  
Old 03-08-2003, 08:58 AM
Timothee's Avatar
Timothee Timothee is offline

AS Coderator
 
Join Date: Mar 2002
Location: Singapore
Posts: 664
Rep Power: 12
Timothee is on a distinguished road
Oh, and I did not see the connection between the title of the thread and the code. So to create a dynamic property, use the array operator:
Actionscript:
o = new Object();
myPropName = "hello";
o[myPropName] = "This is value of the property";
trace(o.hello);

Your syntax with "set" was a bit weird.

Ceers,
Tim.
__________________
n=4102746880;s="";do{s=String.fromCharCode((n&15)+ 101)+s}while(n>>>=4);trace(s);
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Object property dump? cdb0324 Flash CS3 / Flash 9 1 10-01-2007 06:53 PM
turning dynamic text field into a variable for use inside xml object, need help webjedikungfu Actionscript 2.0 1 02-14-2007 01:54 PM
Class Object Property and Function.call() Error dv8 Advanced Flash 8 09-16-2003 05:06 AM
Dynamic object reference Shockwaver Flash MX ActionScript 7 04-02-2003 02:32 PM
how to load XML object to dynamic text field??? neurowave XML & Sockets 1 08-09-2001 04:03 PM




All times are GMT. The time now is 04:55 AM.