PDA

View Full Version : class instantiation + script


benco
12-14-2005, 04:52 AM
Hello,

I've declared a new class in laszlo and I'm trying to instantiate it by using script but each time I try, the debugger return an error 'call to undefined function'... Any ideas ?

<canvas>
...
<class name="NewClass">
...
</class>
...
<script>
...
var x = new NewClass(canvas, {'id':'idNumber'});
</canvas>

Shelby
12-14-2005, 07:09 AM
The following code works for me:


<canvas>

<class name="blah" bgcolor="0xff0000" width="100" height="100"/>

<script>
MyView = new blah(canvas, {x:100, y:100, id:'MyViewId'});
</script>

</canvas>

benco
12-15-2005, 05:03 AM
I've just fix it but it only works when I'm using global variable (without 'var'). If I use 'var', it returns errors like 'undefined function' :s. But why , that's the question ?

Any ideas ... ?

Shelby
12-15-2005, 06:06 AM
Well, if you're defining it in the script tag, what scope are you looking for? If you want the class accessible outside the script tag, you'll need to make it global.

benco
12-15-2005, 06:16 AM
Hence, I know that local variables exist only in the scope where they are defined but here, I thought it was still accessible outside the function of the script because I created a new object (and not a simple number for instance).

I thought it will initially global and should still be accessible because it's possible to retrieve 'views' by property using 'searchSubviews' on canvas for instance).

Shelby
12-15-2005, 06:37 AM
That makes sense. Honestly, I don't know enough about Flash and Laszlo to know what its going to do. If you're accessing it via the subviews, do you need to assign it to a variable? Since you're giving it an ID, maybe you can instantiate it without assigning it to a variable. Using an ID makes the view global anyway.

benco
12-15-2005, 06:41 AM
It is exactly what I was preparing to do :), thanks a lot for your help.