Accessing static variables as hash table

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing static variables as hash table

Viktor Hesselbom
Hello,

in ActionScript 3.0 I can do something like this ClassName["varName"] to get the static variable varName from a class called ClassName.

Now, I'm wondering if something like this is possible with haXe?

I've google'd about it and checked the haxe api with the Hash class and ArrayAccess and what-not.

I know this is bad practice but it would be great if this is possible because I'm currently in the process of porting an ActionScript 3.0 project to haXe/flash.

Thanks for any help,
Viktor Hesselbom

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Accessing static variables as hash table

Franco Ponticelli
Have you tried this?

var v = Reflect.field(ClassName, "varName");

Franco.

On Sun, Nov 9, 2008 at 2:45 PM, Viktor Hesselbom <[hidden email]> wrote:
Hello,

in ActionScript 3.0 I can do something like this ClassName["varName"] to get the static variable varName from a class called ClassName.

Now, I'm wondering if something like this is possible with haXe?

I've google'd about it and checked the haxe api with the Hash class and ArrayAccess and what-not.

I know this is bad practice but it would be great if this is possible because I'm currently in the process of porting an ActionScript 3.0 project to haXe/flash.

Thanks for any help,
Viktor Hesselbom

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Accessing static variables as hash table

Viktor Hesselbom
Hello Franco,

I tried that now and I appear to get some error.

I did a try...catch(e:Dynamic) around it but nothing gets outputted when I try to trace the error.

Viktr

2008/11/9 Franco Ponticelli <[hidden email]>
Have you tried this?

var v = Reflect.field(ClassName, "varName");

Franco.

On Sun, Nov 9, 2008 at 2:45 PM, Viktor Hesselbom <[hidden email]> wrote:
Hello,

in ActionScript 3.0 I can do something like this ClassName["varName"] to get the static variable varName from a class called ClassName.

Now, I'm wondering if something like this is possible with haXe?

I've google'd about it and checked the haxe api with the Hash class and ArrayAccess and what-not.

I know this is bad practice but it would be great if this is possible because I'm currently in the process of porting an ActionScript 3.0 project to haXe/flash.

Thanks for any help,
Viktor Hesselbom

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Accessing static variables as hash table

Franco Ponticelli
I've just tried the following in F9 and it simply works.

class Demo {
static var name = "haXe";
static function main() {
trace(Reflect.field(Demo, "name"));
}
}

Are you compiling for flash? Which version? Are you sure the ClassName reference has not been quoted?

Franco.

On Sun, Nov 9, 2008 at 3:09 PM, Viktor Hesselbom <[hidden email]> wrote:
Hello Franco,

I tried that now and I appear to get some error.

I did a try...catch(e:Dynamic) around it but nothing gets outputted when I try to trace the error.

Viktr

2008/11/9 Franco Ponticelli <[hidden email]>

Have you tried this?

var v = Reflect.field(ClassName, "varName");

Franco.

On Sun, Nov 9, 2008 at 2:45 PM, Viktor Hesselbom <[hidden email]> wrote:
Hello,

in ActionScript 3.0 I can do something like this ClassName["varName"] to get the static variable varName from a class called ClassName.

Now, I'm wondering if something like this is possible with haXe?

I've google'd about it and checked the haxe api with the Hash class and ArrayAccess and what-not.

I know this is bad practice but it would be great if this is possible because I'm currently in the process of porting an ActionScript 3.0 project to haXe/flash.

Thanks for any help,
Viktor Hesselbom

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Accessing static variables as hash table

Viktor Hesselbom
Hello Franco,

Sorry, you're right. It did work. It was something else that gave the error.

Thanks

2008/11/9 Franco Ponticelli <[hidden email]>
I've just tried the following in F9 and it simply works.

class Demo {
static var name = "haXe";
static function main() {
trace(Reflect.field(Demo, "name"));
}
}

Are you compiling for flash? Which version? Are you sure the ClassName reference has not been quoted?

Franco.

On Sun, Nov 9, 2008 at 3:09 PM, Viktor Hesselbom <[hidden email]> wrote:
Hello Franco,

I tried that now and I appear to get some error.

I did a try...catch(e:Dynamic) around it but nothing gets outputted when I try to trace the error.

Viktr

2008/11/9 Franco Ponticelli <[hidden email]>

Have you tried this?

var v = Reflect.field(ClassName, "varName");

Franco.

On Sun, Nov 9, 2008 at 2:45 PM, Viktor Hesselbom <[hidden email]> wrote:
Hello,

in ActionScript 3.0 I can do something like this ClassName["varName"] to get the static variable varName from a class called ClassName.

Now, I'm wondering if something like this is possible with haXe?

I've google'd about it and checked the haxe api with the Hash class and ArrayAccess and what-not.

I know this is bad practice but it would be great if this is possible because I'm currently in the process of porting an ActionScript 3.0 project to haXe/flash.

Thanks for any help,
Viktor Hesselbom

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Accessing static variables as hash table

Franco Ponticelli
No problem.

Franco.

On Sun, Nov 9, 2008 at 3:30 PM, Viktor Hesselbom <[hidden email]> wrote:
Hello Franco,

Sorry, you're right. It did work. It was something else that gave the error.

Thanks


2008/11/9 Franco Ponticelli <[hidden email]>
I've just tried the following in F9 and it simply works.

class Demo {
static var name = "haXe";
static function main() {
trace(Reflect.field(Demo, "name"));
}
}

Are you compiling for flash? Which version? Are you sure the ClassName reference has not been quoted?

Franco.

On Sun, Nov 9, 2008 at 3:09 PM, Viktor Hesselbom <[hidden email]> wrote:
Hello Franco,

I tried that now and I appear to get some error.

I did a try...catch(e:Dynamic) around it but nothing gets outputted when I try to trace the error.

Viktr

2008/11/9 Franco Ponticelli <[hidden email]>

Have you tried this?

var v = Reflect.field(ClassName, "varName");

Franco.

On Sun, Nov 9, 2008 at 2:45 PM, Viktor Hesselbom <[hidden email]> wrote:
Hello,

in ActionScript 3.0 I can do something like this ClassName["varName"] to get the static variable varName from a class called ClassName.

Now, I'm wondering if something like this is possible with haXe?

I've google'd about it and checked the haxe api with the Hash class and ArrayAccess and what-not.

I know this is bad practice but it would be great if this is possible because I'm currently in the process of porting an ActionScript 3.0 project to haXe/flash.

Thanks for any help,
Viktor Hesselbom

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org