antun
02-19-2003, 02:49 PM
Views (and just about any other LZX element) can be instantiated using the new keyword from script:
<canvas>
<class name="mySmiley" resource="smiley.png" />
<simplelayout axis="y" spacing="5" />
<view id="container" width="400" height="300" />
<button>
Add a Smiley
<method event="onclick">
var newX = getRandomPosition( container.width );
var newY = getRandomPosition( container.height );
var smileyPointer = new mySmiley( container, { x: newX } );
smileyPointer.setAttribute( 'y', newY );
</method>
<method name="getRandomPosition" args="max">
return Math.round( Math.random() * max );
</method>
</button>
</canvas>
Attributes can either be declared in the curly braces, or you can use the pointer that the new keyword returns (that's why the x and y attributes are set differently in the above example).
Remember that you may need to explicitly include ready-made components if you instantiate them with script.
Enjoy!
<canvas>
<class name="mySmiley" resource="smiley.png" />
<simplelayout axis="y" spacing="5" />
<view id="container" width="400" height="300" />
<button>
Add a Smiley
<method event="onclick">
var newX = getRandomPosition( container.width );
var newY = getRandomPosition( container.height );
var smileyPointer = new mySmiley( container, { x: newX } );
smileyPointer.setAttribute( 'y', newY );
</method>
<method name="getRandomPosition" args="max">
return Math.round( Math.random() * max );
</method>
</button>
</canvas>
Attributes can either be declared in the curly braces, or you can use the pointer that the new keyword returns (that's why the x and y attributes are set differently in the above example).
Remember that you may need to explicitly include ready-made components if you instantiate them with script.
Enjoy!