View Full Version : delete added images
thipperudra
04-27-2004, 03:55 AM
Hi Antun,
<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>
I am adding smiley view by clicking add a smiley button. But I want to delete those added smiley images dynamically.How can i remove those created(added) smileys by clicking remove button.
Thanks in advance,
Rudresh
antun
04-27-2004, 08:24 AM
The destroy() method deletes a node. view inherits this from LzNode. If you plan to delete all dynamically created views, you should record the pointers to them that are returned when the view is constructed. I'm using an array to store them:
<canvas>
<class name="mySmiley" resource="smiley.png" />
<simplelayout axis="y" spacing="5" />
<view id="container" width="400" height="300" />
<button id="adderButt">
Add a Smiley
<method event="oninit">
this.pointersToImages = new array();
</method>
<method event="onclick">
var newX = getRandomPosition( container.width );
var newY = getRandomPosition( container.height );
var smileyPointer = new mySmiley( container, { x: newX } );
smileyPointer.setAttribute( 'y', newY );
this.pointersToImages.push( smileyPointer );
</method>
<method name="getRandomPosition" args="max">
return Math.round( Math.random() * max );
</method>
</button>
<button>Delete all smileys
<method event="onclick">
for ( var b in adderButt.pointersToImages ) {
adderButt.pointersToImages[b].destroy();
}
</method>
</button>
</canvas>
-Antun
thipperudra
04-27-2004, 09:06 PM
Thanks alot antun it working fine:)
-Rudresh
OLaszloFan
08-21-2006, 05:54 AM
Hi All:
I was searching the Forum for examples of destroying views and found the code example below. However, after generating the views, the delete all views
button does not initiate the change. Does anyone
have any suggestions on what needs to be changed
or other suggestions. This is an old example.
I am using 3.3.3 now.
Best Regards,
Patrick
<canvas>
<class name="mySmiley" resource="smiley.png" />
<simplelayout axis="y" spacing="5" />
<view id="container" width="400" height="300" />
<button id="adderButt">
Add a Smiley
<method event="oninit">
this.pointersToImages = new array();
</method>
<method event="onclick">
var newX = getRandomPosition( container.width );
var newY = getRandomPosition( container.height );
var smileyPointer = new mySmiley( container, { x: newX } );
smileyPointer.setAttribute( 'y', newY );
this.pointersToImages.push( smileyPointer );
</method>
<method name="getRandomPosition" args="max">
return Math.round( Math.random() * max );
</method>
</button>
<button>Delete all smileys
<method event="onclick">
for ( var b in adderButt.pointersToImages ) {
adderButt.pointersToImages[b].destroy();
}
</method>
</button>
</canvas>
OLaszloFan
08-21-2006, 06:09 AM
All:
After additional debugging time, I solved the problem.
Ends up the new array() statement needed to be
new Array().
i.e. Capital letter issue strikes again.
Therefore, the delete view example works with this change.
Best Regards,
Patrick
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.