[Laszlo-user] create a class by name
James Robey
jrobey at laszlosystems.com
Fri Oct 12 15:58:07 PDT 2007
So Noted. I'm using the global[cname] variant now, so i'll port.
Thanks!
On Oct 12, 2007, at 1:19 PM, P T Withington wrote:
> Thanks Eliot! You are correct. (I was thinking in Javascript,
> thanks for spotting this.)
>
> If you define a class:
>
> <class name="TestClass" ...
>
> This will define a Javascript class in the `lz` package. So yes,
> if you are trying to dynamically instantiate the LZX class
> `TestClass` in script, my examples should read:
>
> new lz.TestClass();
>
> Or:
>
> var theclass = lz.TestClass;
> ...
> new theclass();
>
> Or:
>
> var theclassname = "TestClass";
> ...
> new lz[theclassname]();
>
> ---
>
> For backwards compatibility with LPS 3, we also define LZX classes
> globally (if they do not conflict with an existing global
> definition). That will eventually be phased out, so the above is
> more correct.
>
> On 2007-10-12, at 15:39 EDT, Elliot Winard wrote:
>
>> I thought it was preferable to use class objects that are in 'lz'
>> object rather than global[classname]
>>
>> Are the lz.* potentially going to go away?
>> -e
>>
>> P T Withington wrote:
>>> eval is very limited in the swf runtime. It can only evaluate
>>> var and member expressions.
>>>
>>> Are you just trying to create a particular class, or do you need
>>> the class to be variable, or do you need the name of the class to
>>> be a variable? E.g., you can just say:
>>>
>>> new TestClass();
>>>
>>> Or:
>>>
>>> var theclass = TestClass;
>>> ...
>>> new theclass();
>>>
>>> Or:
>>>
>>> var theclassname = "TextClass";
>>> ...
>>> new global[theclassname]();
>>>
>>> All of these work. Your mechanism is what is used to evaluate a
>>> general expression, and is required because of the limited nature
>>> of eval in the swf runtime. It is basically calling back to the
>>> server, having the server compile the expression, and then
>>> loading the compiled code to evaluate it.
>>>
>>> In the DHTML runtime, eval is fully-featured, but remember it is
>>> a security hole. If you allow arbitrary user input to be
>>> evalled, you really have no control...
>>>
>>>
>>> On 2007-10-12, at 14:12 EDT, Ruben Reusser wrote:
>>>
>>>> Hi:
>>>>
>>>> Is it possible to create a class by name in OpenLaszlo? I tried:
>>>>
>>>> eval("new TestClass()");
>>>>
>>>> but this does not work. The only solution I could find was the
>>>> following:
>>>>
>>>> loader.request( { lz_load : false,lzt : "eval",proxied:
>>>> true,url: "__debugger.lzx",lz_script : "#file interactive-eval-0
>>>> \nnew TestClass()"} );
>>>>
>>>> not my favorite approach.
>>>>
>>>> Ruben
>>>>
>>>
>
More information about the Laszlo-user
mailing list