Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help understanding a "persistent mousedown."

1 view
Skip to first unread message

-Lost

unread,
Mar 11, 2007, 5:58:59 AM3/11/07
to
See, in ActionScript (Flash) I was able to do it this way:

frame 1 {
this.onEnterFrame = function () {
if (buttonIsDown) {
i += 1;
duplicateMovieClip(_root.layer.target, 'variable_name' + i, i);
// last argument is depth
}
};
}

Of course the button:
button 4 {
on (press) {
var buttonIsDown = true;
}
on (release) {
var buttonIsDown = false;
}
}

Doing, *basically*, the same thing in JavaScript results in the onmousedown being carried
out for *quite some time*, then, depending on how quickly I released the mouse button the
script runs out of execution time or continues on with it being false.

So, inevitably I was left with a script that attempted to close your browser each time it
ran.

Can anyone steer me in the general direction of having a persistent mousedown event? Not
a drag and drop, but perhaps just the drag, um, minus it needing to move?

-Lost


-Lost

unread,
Mar 11, 2007, 2:04:28 PM3/11/07
to
It never dawned on me to at least provide a crude (as crude is as good as it gets)
JavaScript example.

var mouseIsDown = true;
function start_md()
{
while (mouseIsDown == true)
{
document.getElementById('filler').innerHTML += ' text ';
}
}
function stop_md()
{
mouseIsDown = false;
}


window.onload = function()
{
document.onmousedown = start_md;
document.onmouseup = stop_md;
}

<p id="filler"></p>

This of course has major flaws. The greatest of which is that the while takes off
considerably faster than what Firefox seems to like. Finally, after a few to many seconds
later it appears to work. So this "chaotic" behavior is unsuitable and undesirable.

Any ideas?

-Lost


VK

unread,
Mar 11, 2007, 5:23:54 PM3/11/07
to

Browsers do not update graphics context (screen content) until after
the current execution thread is finished. Until it's finished the DOM
changes are being accumulated but not reflected on the screen. The
most commonly used way to overcome this - I would say weakness - is
using micro-breaks over setTimeout. In your code change:

> function start_md()
> {
> while (mouseIsDown == true)
> {
> document.getElementById('filler').innerHTML += ' text ';
> }}

to

function start_md() {
window.setTimeout(addContent, 60);
}

function addContent() {


document.getElementById('filler').innerHTML += ' text ';

if (mouseIsDown) {
window.setTimeout(addContent, 60);
}
}

the needed micro-break will make the magic for you.

<FAQENTRY>
Would FAQ maintainer consider adding relevant FAQ? It could be like
"I'm changing my page but nothing is changing on the screen. Why?"
I could write the initial short text.
IMHO this issue by its frequency and especially by its "mysterious
nastiness" is well qualified for a FAQ.
</FAQENTRY>

FAQEditor

unread,
Mar 11, 2007, 6:16:28 PM3/11/07
to
VK said the following on 3/11/2007 5:23 PM:

<snip>

> <FAQENTRY>
> Would FAQ maintainer consider adding relevant FAQ? It could be like
> "I'm changing my page but nothing is changing on the screen. Why?"
> I could write the initial short text.
> IMHO this issue by its frequency and especially by its "mysterious
> nastiness" is well qualified for a FAQ.
> </FAQENTRY>

Somewhere in the archives (I can't find it right now) there are several
threads where I asked about an entry of why the display isn't being
updated.

Post a short text and lets see where it goes. I don't have a problem
adding a new entry.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
FAQ Notes: http://www.jibbering.com/faq/faq_notes/faq_notes.html
ECMAScript Language Specification via FAQ2.6

-Lost

unread,
Mar 11, 2007, 7:31:01 PM3/11/07
to
"VK" <school...@yahoo.com> wrote in message
news:1173648234.7...@c51g2000cwc.googlegroups.com...

I never thought of this. Thank you.

-Lost


-Lost

unread,
Mar 11, 2007, 7:32:33 PM3/11/07
to
"FAQEditor" <clj...@ctvea.net> wrote in message
news:96KdnWWfEOw...@giganews.com...

> VK said the following on 3/11/2007 5:23 PM:
>
> <snip>
>
>> <FAQENTRY>
>> Would FAQ maintainer consider adding relevant FAQ? It could be like
>> "I'm changing my page but nothing is changing on the screen. Why?"
>> I could write the initial short text.
>> IMHO this issue by its frequency and especially by its "mysterious
>> nastiness" is well qualified for a FAQ.
>> </FAQENTRY>
>
> Somewhere in the archives (I can't find it right now) there are several threads where I
> asked about an entry of why the display isn't being updated.
>
> Post a short text and lets see where it goes. I don't have a problem adding a new entry.

Unless there is something I am missing, as in an apparent flaw, VK's suggestion worked
wonders.

If this code will be the basis for the write-up, then I would definitely like to see it
written up, eloquently.

-Lost


0 new messages