In the attached script (part of a framework), custom objects of type scratchBlock are created. They should have a function 'render' assigned, and they do. But aScratchBlock.render() always seems to trigger the render function on the last created object of type scratchBlock.
Any ideas?
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><head><title>WebScratch Sandbox</title><link href="style.css" rel="stylesheet" type="text/css"><script type="text/javascript" src="editor.js"></script></head><body onLoad="app_init()" onMouseMove="app_mouseMove(event)"><div id="scriptEditor"></div></body></html>
That doesn't work, because there only is one version of scratchBlock_render, while with the way you have it coded, you need a new one for each object. You are looking for prototype object.
Great wit and madness are near allied, and fine a line their bounds divide.
This makes me think there is a problem with the this.DOMobj = document.getElementById(...);
Is it possible that outside of the scratchBlock() object definition, aScratchBlock.DOMobj is handled as a copy of the HTML DOM object instead of a reference to the actual element on the page?
This is what it seems to be - all properties of each scratchBlock object seem to have the desired values when running the script - the positions on the screen are just not updating...
Last edited by Declan1991; 03-29-2010 at 06:07 PM.
It seems I am not allowed to edit my own post, so I have to post a new one It says 'you may edit your posts' at the bottom of the page though...
The title is also not describing my problem anymore - this happens when you think you've found problem but you're proven wrong afterwards. I should have done more testing before posting, sorry. I also noticed my last post got edited?
I accidently posted a slightly wrong version of my code above, this is the version in which the scratchBlock render method does not exist. (simply shrunk it down until there were only two lines of code remaining, then replaced the two references to aScratchObject.render() with the actual code.)
I did not mention it yet, but I really appreciate your help. Hopefully I'll be able to help others on this forum too, on surfaces I am slightly better at I know JavaScript just enough for creating dynamic forms and pages, but once it comes to this...
And I see I did not describe my script too well, here it goes:
When a new scratchBlock object is created, a piece of HTML is added to the div element scriptEditor.
This new div should be draggable, but it's important to store the css properties as properties of the object for further reference in my project.
aScratchBlock.DOMobj should contain a reference to document.getElementById('theScratchBlock'). To me it seems aScratchBlock.DOMobj does not contain a reference to the HTML element, but somehow a copy of it - I can edit it style properties, it stores them, the div's just don't move...
The last created scratchBlock always works perfectly...
Bookmarks