Ask a Question related to Macromedia Director Basics, Design and Development.
-
Editz webforumsuser@macromedia.com #1
Custom cursor snapping to grid?
Hi I have done this as an example.
[url]http://www.schoolyardrules.com/director/cursor.htm[/url]
[url]http://www.schoolyardrules.com/director/cursor.dir[/url]
but would like the cursor to snap to a grid so that it is only ever around one of the squares.
Similiar to the interface on a mobile phone.
I dont want the cursor to be inbetween - just on one of the squares.
I want to use this in conjuction with keyboard presses rather than mouse movement.
So it should be something like this:
left arrow key press - move cursor 50 pixels left
right arrow key press - move cursor 50 pixels right
up arrow key press - move cursor 50 pixels up
down arrow key press - move cursor 50 pixels down
but I don't know how to code it.
Any ideas?
Thanks
Editz webforumsuser@macromedia.com Guest
-
Cursor in a mx:Grid
Hello, How can i put a Vertical Cursor in a Grid container? I have to set the height of the Grid, i want to see the next rows when i go down with... -
Snapping to Text Frame Baseline Grid
Hi all! (CS2, OSX, G5) I had to create text boxes with their own baseline grid (via text frame options). This grid in my case needs to be offset... -
Moving Custom Cursor with the key board?
Hi, me again. I want to move a custom cursor or just a sprite using the arrow keys and the enter key instead of a mouse down / click. I have... -
String not available/custom cursor
Hi! I have problem when loading a .dcr file on web. I use WinNT, Director 8.0, and IE6.0 An error message saying "String not available"... -
Creating a Custom Cursor
I used photoshop to create a custom black and white cursor. It is 16x16 grayscale. It's saved as a bitmap. I guess that makes it 8 bit instead of 1... -
Joe #2
Custom cursor snapping to grid?
Hi I have done this as an example.
[url]http://www.schoolyardrules.com/director/cursor.htm[/url]
[url]http://www.schoolyardrules.com/director/cursor.dir[/url]
but would like the cursor to snap to a grid so that it is only ever around
one of the squares.
Similiar to the interface on a mobile phone.
I dont want the cursor to be inbetween - just on one of the squares.
I want to use this in conjuction with keyboard presses rather than mouse
movement.
So it should be something like this:
left arrow key press - move cursor 50 pixels left
right arrow key press - move cursor 50 pixels right
up arrow key press - move cursor 50 pixels up
down arrow key press - move cursor 50 pixels down
but I don't know how to code it.
Any ideas?
Thanks
Joe Guest
-
Joe #3
Custom cursor snapping to grid?
Hi I have done this as an example.
[url]http://www.schoolyardrules.com/director/cursor.htm[/url]
[url]http://www.schoolyardrules.com/director/cursor.dir[/url]
but would like the cursor to snap to a grid so that it is only ever around
one of the squares.
Similiar to the interface on a mobile phone.
I dont want the cursor to be inbetween - just on one of the squares.
I want to use this in conjuction with keyboard presses rather than mouse
movement.
So it should be something like this:
left arrow key press - move cursor 50 pixels left
right arrow key press - move cursor 50 pixels right
up arrow key press - move cursor 50 pixels up
down arrow key press - move cursor 50 pixels down
but I don't know how to code it.
Any ideas?
Thanks
Joe Guest
-
Mats #4
Re: Custom cursor snapping to grid?
I havent seen any answer on this one, but sorry if I repeat something> So it should be something like this:
>
> left arrow key press - move cursor 50 pixels left
> right arrow key press - move cursor 50 pixels right
> up arrow key press - move cursor 50 pixels up
> down arrow key press - move cursor 50 pixels down
>
> but I don't know how to code it.
someone already said - new newsreader, recently formatted hard drive and
so on...
You are half way there. Make the actual system cursor invisible (cursor
200) first, then use your red frame, or any other sprite, as "cursor"
instead.
the on keyDown-handler can be used for moving the cursor sprite. Use
"the keyCode" with the right key number to move the cursor.
Something like
on keyDown
case (the key) of
123:sprite(cursorsprite).locH=sprite(cursorsprite) .locH-50
124:sprite(cursorsprite).locH=sprite(cursorsprite) .locH+50
-- keep doing cursorsprite-moving commands here
end case
end
in the movie script or the frame script should do it. NB! Incomplete
lingo code - didnīt have access to Director when writing this. I have
used a variable for representing the sprite channel number but you might
want to hardcode the number in instead.
Actually, since you plan to control the "cursor" with key commands you
might not even need to hide the system cursor. Not hiding the system
cursor would be a good approach if you plan to publish the dir-file as
shockwave and place it on an HTML page.
Mats Guest
-
Mats #5
Re: Custom cursor snapping to grid?
I havent seen any answer on this one, but sorry if I repeat something> So it should be something like this:
>
> left arrow key press - move cursor 50 pixels left
> right arrow key press - move cursor 50 pixels right
> up arrow key press - move cursor 50 pixels up
> down arrow key press - move cursor 50 pixels down
>
> but I don't know how to code it.
someone already said - new newsreader, recently formatted hard drive and
so on...
You are half way there. Make the actual system cursor invisible (cursor
200) first, then use your red frame, or any other sprite, as "cursor"
instead.
the on keyDown-handler can be used for moving the cursor sprite. Use
"the keyCode" with the right key number to move the cursor.
Something like
on keyDown
case (the key) of
123:sprite(cursorsprite).locH=sprite(cursorsprite) .locH-50
124:sprite(cursorsprite).locH=sprite(cursorsprite) .locH+50
-- keep doing cursorsprite-moving commands here
end case
end
in the movie script or the frame script should do it. NB! Incomplete
lingo code - didnīt have access to Director when writing this. I have
used a variable for representing the sprite channel number but you might
want to hardcode the number in instead.
Actually, since you plan to control the "cursor" with key commands you
might not even need to hide the system cursor. Not hiding the system
cursor would be a good approach if you plan to publish the dir-file as
shockwave and place it on an HTML page.
Mats Guest
-
Joe #6
Re: Custom cursor snapping to grid?
"Mats" <mats.takethisaway@removethis.telia.com> wrote in message
news:UF8wb.34919$mU6.118293@newsb.telia.net...Hi thanks for the reply.>>> > So it should be something like this:
> >
> > left arrow key press - move cursor 50 pixels left
> > right arrow key press - move cursor 50 pixels right
> > up arrow key press - move cursor 50 pixels up
> > down arrow key press - move cursor 50 pixels down
> >
> > but I don't know how to code it.
> I havent seen any answer on this one, but sorry if I repeat something
> someone already said - new newsreader, recently formatted hard drive and
> so on...
>
> You are half way there. Make the actual system cursor invisible (cursor
> 200) first, then use your red frame, or any other sprite, as "cursor"
> instead.
> the on keyDown-handler can be used for moving the cursor sprite. Use
> "the keyCode" with the right key number to move the cursor.
> Something like
>
> on keyDown
> case (the key) of
> 123:sprite(cursorsprite).locH=sprite(cursorsprite) .locH-50
> 124:sprite(cursorsprite).locH=sprite(cursorsprite) .locH+50
> -- keep doing cursorsprite-moving commands here
> end case
> end
>
> in the movie script or the frame script should do it. NB! Incomplete
> lingo code - didnīt have access to Director when writing this. I have
> used a variable for representing the sprite channel number but you might
> want to hardcode the number in instead.
> Actually, since you plan to control the "cursor" with key commands you
> might not even need to hide the system cursor. Not hiding the system
> cursor would be a good approach if you plan to publish the dir-file as
> shockwave and place it on an HTML page.
It isnt working when I try this:
on exitFrame me
go the frame
end
on keyDown
case (the key) of
123sprite(cursorsprite).locH=sprite(cursorsprite). locH-50
124sprite(cursorsprite).locH=sprite(cursorsprite). locH+50
-- keep doing cursorsprite-moving commands here
end case
end
I just get this error alert when I run the it:
Script error: Variable used before assigned a value
123:sprite(cursorsprite)?.locH=sprite(cursorsprite ).locH-50
How do you mean 'hard code the number'?
Thanks for your help so far.
Joe Guest
-
Joe #7
Re: Custom cursor snapping to grid?
"Mats" <mats.takethisaway@removethis.telia.com> wrote in message
news:UF8wb.34919$mU6.118293@newsb.telia.net...Hi thanks for the reply.>>> > So it should be something like this:
> >
> > left arrow key press - move cursor 50 pixels left
> > right arrow key press - move cursor 50 pixels right
> > up arrow key press - move cursor 50 pixels up
> > down arrow key press - move cursor 50 pixels down
> >
> > but I don't know how to code it.
> I havent seen any answer on this one, but sorry if I repeat something
> someone already said - new newsreader, recently formatted hard drive and
> so on...
>
> You are half way there. Make the actual system cursor invisible (cursor
> 200) first, then use your red frame, or any other sprite, as "cursor"
> instead.
> the on keyDown-handler can be used for moving the cursor sprite. Use
> "the keyCode" with the right key number to move the cursor.
> Something like
>
> on keyDown
> case (the key) of
> 123:sprite(cursorsprite).locH=sprite(cursorsprite) .locH-50
> 124:sprite(cursorsprite).locH=sprite(cursorsprite) .locH+50
> -- keep doing cursorsprite-moving commands here
> end case
> end
>
> in the movie script or the frame script should do it. NB! Incomplete
> lingo code - didnīt have access to Director when writing this. I have
> used a variable for representing the sprite channel number but you might
> want to hardcode the number in instead.
> Actually, since you plan to control the "cursor" with key commands you
> might not even need to hide the system cursor. Not hiding the system
> cursor would be a good approach if you plan to publish the dir-file as
> shockwave and place it on an HTML page.
It isnt working when I try this:
on exitFrame me
go the frame
end
on keyDown
case (the key) of
123sprite(cursorsprite).locH=sprite(cursorsprite). locH-50
124sprite(cursorsprite).locH=sprite(cursorsprite). locH+50
-- keep doing cursorsprite-moving commands here
end case
end
I just get this error alert when I run the it:
Script error: Variable used before assigned a value
123:sprite(cursorsprite)?.locH=sprite(cursorsprite ).locH-50
How do you mean 'hard code the number'?
Thanks for your help so far.
Joe Guest
-
Mats #8
Re: Custom cursor snapping to grid?
Joe wrote:
Hm. Your scripts look strange in my newsreader. Your lines lack the> It isnt working when I try this:
>
> on keyDown
> case (the key) of
> 123sprite(cursorsprite).locH=sprite(cursorsprite). locH-50
> 124sprite(cursorsprite).locH=sprite(cursorsprite). locH+50
> -- keep doing cursorsprite-moving commands here
> end case
> end
>
> I just get this error alert when I run the it:
> Script error: Variable used before assigned a value
>
> 123:sprite(cursorsprite)?.locH=sprite(cursorsprite ).locH-50
colon : sign that divides up the case alternative from its command.
However, in the text that you pasted from the error dialog the colon
char is there, so I conclude that you must have had it in your original
script.
>> I have used a variable for representing the sprite channel
>>number but you might want to hardcode the number in instead.Again, you are half way there. The error and your questions are> How do you mean 'hard code the number'?
interconnected.
As you can see in your error dialog box, there is a question mark just
after the word "cursorsprite". The question mark in an error dialog
appears **right after the first thing that the lingo interpreter doesnīt
understand**. So always look for the question mark. Unfortunately, the
place where the lingo interpreter stops understanding isnīt necessarily
where the error is.
In this case, the error is obvious, even though there is nothing wrong
with that particular line per se. But: Director says you have used a
variable before you assigned a value to it, and that is absolutely
right. The word "cursorsprite" is in fact a variable, and you have not
assigned a value to it. Neither have you declared the variable,
something that you need to do separately if you want to use it in more
than one place.
See below for explanation about variables, but the really quick fix for
this error is to do something like this:
123:sprite(14).locH=sprite(14).locH-50
assuming the magenta (red? lilac? canīt quite tell from my screen) frame
that you want to move is in sprite channel number 14.
"Hard coding" in this case is simply to write the actual number of the
sprite instead of using a variable for it. However, I strongly recommend
that you learn how to use variables if this is new to you. Recommended
reading is here below ;-)
Recommended reading: ******** How to use variables, by Mats ********
A variable, as you may know, is just something that works like the
memory button on your old calculator. The memory button is used for
storing numbers. A variable can be used for storing numbers too, or
text, or just about anything that you can think of that can can be used
inside Director (thatīs a lot of things). Now, Director complains that
this variable doesnīt have any value yet. Assigning a value to a
variable is easy, just use the equals sign =. This:
cursorsprite=14
will make Director understand that the variable named cursorsprite
should contain the value 14 - by the way, to Director this is an integer
, since it has no quotes around it and it has no decimal point.
You must assign the value to a variable inside a handler. This handler
can be just about anywhere, but since we are in a frame script, why not
put it in the beginsprite handler.
on beginSprite me
cursorsprite=14
end
If you do this step, you will still get an error. Why? Because Director
forgets about the new variable as soon as it has stepped through the
beginsprite handler (or whatever handler you used). It is a so called
local variable, and is only valid for the handler it resides in.
A variable that you want to use in several handlers or scripts must be a
"property variable" or a "global variable". A global variable is valid,
and accessable, for as long as you run Director/the projector/the
shockwave object. This is probably what you want to start using.
A property variable is valid for the script instance, but if this sounds
like greek to you, just forget it for now and think of globals. How to
declare them then? Like this:
global cursorsprite
Now, THIS line does not need to be in any handler. In fact, itīs a lot
better if you just put it on its own, preferably as the first line in
your frame script, where you have the rest of your code. Your script
will now look something like this:
-------------------
global cursorsprite
on beginsprite me
cursorsprite=14
end
on exitFrame me
go the frame
end
on keyDown me
case (the keyCode) of
123:sprite(cursorsprite).locH=sprite(cursorsprite) .locH-50
124:sprite(cursorsprite).locH=sprite(cursorsprite) .locH+50
125:sprite(cursorsprite).locV=sprite(cursorsprite) .locV-50
126:sprite(cursorsprite).locV=sprite(cursorsprite) .locV+50
-- this is getting better all the time, right?
end case
end
------------------
Why use a variable? Well...
1. In this case you may want to reference the cursorspriteīs sprite
number from several places in your movie, and words are almost always
easier to remember than numbers, right?
2. Also, if after a while you decide that it would be better to move
your cursor sprite to another sprite channel in the score, there are
already eight places where you would have to write the new channel
number if you had it "hard coded", that is, written directly into the
code. That gives us eight (8) possible chances of typo errors. We want
to avoid typo errors when coding, since it is already hard enough as it
is to get the code right, right?
With variables, you just need to change it in one place. Good, huh?
P.S. I wrongly used "the key" in my script. It has to be "the keyCode"
if you want to use the arrow keys. "the key" is the actual character,
"the keyCode" is the number of the physical key on the keyboard (not the
ascii number, the arrow keys donīt have ascii numbers).
I have a nice little "keytracker Xtra" that you can download from my
site where you can see both "the keyCode" and "the key" by simply
pushing keys on your keyboard. You can even run it directly in a browser
window from here:
<http://www.digitalakuten.com/dlds/keytrackerXtra.dcr>
For Mac: <http://www.digitalakuten.com/dlds/keytrackerXtra.sit>
For Windows: <http://www.digitalakuten.com/dlds/keytrackerXtra.zip>
Just put it in your Xtras folder inside Director and restart Director.
You will find the Xtra (itīs a MIAW Xtra) under your Xtras menu in Director.
D.S.
Mats Guest
-
Mats #9
Re: Custom cursor snapping to grid?
Joe wrote:
Hm. Your scripts look strange in my newsreader. Your lines lack the> It isnt working when I try this:
>
> on keyDown
> case (the key) of
> 123sprite(cursorsprite).locH=sprite(cursorsprite). locH-50
> 124sprite(cursorsprite).locH=sprite(cursorsprite). locH+50
> -- keep doing cursorsprite-moving commands here
> end case
> end
>
> I just get this error alert when I run the it:
> Script error: Variable used before assigned a value
>
> 123:sprite(cursorsprite)?.locH=sprite(cursorsprite ).locH-50
colon : sign that divides up the case alternative from its command.
However, in the text that you pasted from the error dialog the colon
char is there, so I conclude that you must have had it in your original
script.
>> I have used a variable for representing the sprite channel
>>number but you might want to hardcode the number in instead.Again, you are half way there. The error and your questions are> How do you mean 'hard code the number'?
interconnected.
As you can see in your error dialog box, there is a question mark just
after the word "cursorsprite". The question mark in an error dialog
appears **right after the first thing that the lingo interpreter doesnīt
understand**. So always look for the question mark. Unfortunately, the
place where the lingo interpreter stops understanding isnīt necessarily
where the error is.
In this case, the error is obvious, even though there is nothing wrong
with that particular line per se. But: Director says you have used a
variable before you assigned a value to it, and that is absolutely
right. The word "cursorsprite" is in fact a variable, and you have not
assigned a value to it. Neither have you declared the variable,
something that you need to do separately if you want to use it in more
than one place.
See below for explanation about variables, but the really quick fix for
this error is to do something like this:
123:sprite(14).locH=sprite(14).locH-50
assuming the magenta (red? lilac? canīt quite tell from my screen) frame
that you want to move is in sprite channel number 14.
"Hard coding" in this case is simply to write the actual number of the
sprite instead of using a variable for it. However, I strongly recommend
that you learn how to use variables if this is new to you. Recommended
reading is here below ;-)
Recommended reading: ******** How to use variables, by Mats ********
A variable, as you may know, is just something that works like the
memory button on your old calculator. The memory button is used for
storing numbers. A variable can be used for storing numbers too, or
text, or just about anything that you can think of that can can be used
inside Director (thatīs a lot of things). Now, Director complains that
this variable doesnīt have any value yet. Assigning a value to a
variable is easy, just use the equals sign =. This:
cursorsprite=14
will make Director understand that the variable named cursorsprite
should contain the value 14 - by the way, to Director this is an integer
, since it has no quotes around it and it has no decimal point.
You must assign the value to a variable inside a handler. This handler
can be just about anywhere, but since we are in a frame script, why not
put it in the beginsprite handler.
on beginSprite me
cursorsprite=14
end
If you do this step, you will still get an error. Why? Because Director
forgets about the new variable as soon as it has stepped through the
beginsprite handler (or whatever handler you used). It is a so called
local variable, and is only valid for the handler it resides in.
A variable that you want to use in several handlers or scripts must be a
"property variable" or a "global variable". A global variable is valid,
and accessable, for as long as you run Director/the projector/the
shockwave object. This is probably what you want to start using.
A property variable is valid for the script instance, but if this sounds
like greek to you, just forget it for now and think of globals. How to
declare them then? Like this:
global cursorsprite
Now, THIS line does not need to be in any handler. In fact, itīs a lot
better if you just put it on its own, preferably as the first line in
your frame script, where you have the rest of your code. Your script
will now look something like this:
-------------------
global cursorsprite
on beginsprite me
cursorsprite=14
end
on exitFrame me
go the frame
end
on keyDown me
case (the keyCode) of
123:sprite(cursorsprite).locH=sprite(cursorsprite) .locH-50
124:sprite(cursorsprite).locH=sprite(cursorsprite) .locH+50
125:sprite(cursorsprite).locV=sprite(cursorsprite) .locV-50
126:sprite(cursorsprite).locV=sprite(cursorsprite) .locV+50
-- this is getting better all the time, right?
end case
end
------------------
Why use a variable? Well...
1. In this case you may want to reference the cursorspriteīs sprite
number from several places in your movie, and words are almost always
easier to remember than numbers, right?
2. Also, if after a while you decide that it would be better to move
your cursor sprite to another sprite channel in the score, there are
already eight places where you would have to write the new channel
number if you had it "hard coded", that is, written directly into the
code. That gives us eight (8) possible chances of typo errors. We want
to avoid typo errors when coding, since it is already hard enough as it
is to get the code right, right?
With variables, you just need to change it in one place. Good, huh?
P.S. I wrongly used "the key" in my script. It has to be "the keyCode"
if you want to use the arrow keys. "the key" is the actual character,
"the keyCode" is the number of the physical key on the keyboard (not the
ascii number, the arrow keys donīt have ascii numbers).
I have a nice little "keytracker Xtra" that you can download from my
site where you can see both "the keyCode" and "the key" by simply
pushing keys on your keyboard. You can even run it directly in a browser
window from here:
<http://www.digitalakuten.com/dlds/keytrackerXtra.dcr>
For Mac: <http://www.digitalakuten.com/dlds/keytrackerXtra.sit>
For Windows: <http://www.digitalakuten.com/dlds/keytrackerXtra.zip>
Just put it in your Xtras folder inside Director and restart Director.
You will find the Xtra (itīs a MIAW Xtra) under your Xtras menu in Director.
D.S.
Mats Guest



Reply With Quote

