Having problems with this.startdrag();

I’m trying to make a movie clip follow the mouse and a lot of the help files and forum posts say that the easiest way to do this is to use the drag function. But when I have

onClipEvent (load) {

the movie clip doesn’t follow the mouse, but it diagonally off to the left or right depending on where the mouse enters the movie clip. How do you get it to follow the mouse exactly? Thanks for any help.

                                             the kza


onClipEvent (enterFrame) instead of load.

This can make or break your code. Using the enterFrame updates the position everytime the frame is entered. If your movie is 1 frame, it will constantly loop that frame so the position will be updated constantly.

HINT: The higher your frame rate, the better it follows (I usually use around 30 FPS).

Thanks for the help. I can now get the instance to follow the mouse, but I have encountered a new problem relating to the drag. When the instance follows the mouse, it follows it but at a position away from the mouse. How far away from the mouse it is depends on where I place the instance on the stage. I can get the instance to correlate to the mouse position by placing it above and to the left of the stage. Do I have to leave the instance there or is there a better way to get it to center on the mouse? Again, thanks for all of your help.

                                         the kza

Hmmm, can you post a .fla so I can see exactly what you mean?

Here’s the fla. I hope you can figure out what’s wrong with it because I sure can’t. That’s what I get for jumping into the deep end of Actionscript without knowing what I’m doing. Thanks again for your help.

Ok, instead of going through the problem of rezipping your file I will just tell you what to do.

Remove the actions from the clip itself, so there aren’t any actions on your clip (that have to deal with dragging). Right click on the frame and choose “Actions” then add these actions…

startDrag("sword", true);
Drag movie clip instance "Sword"
true = lock mouse to center of clip.

This works like a charm:)
By The Way: Did you draw that sword yourself? If so, that is VERY nice flash art, I can’t draw for diddly in Flash…haha:P

It sure did! Thanks for all the help lostinbeta! I got all the dragging to work the way I wanted and I can finally try to get the last part working. I am sad to say that I was not the one who drew that sword. I conned a friend into drawing it for me. He also drew a bunch of other stuff that I took out to make the fla smaller. When I finish the fla (hopefully), I’ll put up a link to it. Again, thanks for all the help. This forum is an awesome place to get help. Well, I’m off to attempt to finish it.
the kza

Your welcome kza. I am here to help.

Good luck on the rest of your file:)

I got it to work the way I wanted. I’m going to add some dialogue and stuff later but the core of the file works the way I want it to. I’d like to know what you think or if you have any suggestions for improvement.


Um, very gory…haha. I like the way the blood is drawn too. One downfall is that it is a pain to switch between weapons. You should have on onKeyPress command to detatch a weapon so you can easily choose the other one, instead of guess and click over and over.

You should also draw the bat in Flash, it would add to the effect instead of an image.

neat effect. As far as suggestions… hmm… I would make sure of the swicthing weapons thing (like lostinbeta said). Also, the hittest is slightly off as I could tap with the point of my sword and not draw blood. (I realize that maybe that part of the sword may not be as sharp. Bad Blacksmith. hehehhehe). I was wondering what is is I am striking. Is this one of those ink blot psychiatry tests? If it is, I like it… I can make that be anything I want. Oh boy… It’s late. Off to bed I go, don’t think Im making sense.

I thought it was a bat…haha. I really can’t tell what it is though. That is why I said to draw the image in Flash. It might be more recognizable and the pixels won’t stretch.

The bat is actually a jpeg of a figure from the game Mageknight. Some friends of mine have a website for it and I’m making the flash movie for them. The bat is actually Yellow Imp, which is the mascot of their site, so it has to stay in. If you’re bored enough and want to check out their site here it is:
The reason the sword doesn’t seem to hit properly is because I don’t know how to do true hit detection yet so it still relies on the mouse pointer to click the imp, which is a button. I’m currently trying to improve it by throwing in some little things, like a title, etc. I’m also trying to get various dialogue to appear depending on how many times you’ve hit Yellow Imp. I haven’t gotten it quite working, but I want mess around with some different ideas before crying uncle. Thanks for your time to look at it and make suggestions.

Cool weapons. :slight_smile:

Seriously, I like the way you’ve drawn these. And I’d also agree that if you could get a line art image of the bat as well, it would probably make it look more in context. Maybe you could stylise him a bit, so he’s still recogniseable as that particular bat. Does he have any distinguishing features? :slight_smile:

The bat is a mascot for a friend’s site and the image you beat in the game is the same image they use on the site so it has to stay the same. Right now I’m having some trouble getting the key presses to work the way I want them to. The code I’m using is:

//on the mace instance
onClipEvent (enterFrame) {
if (Key.isDown(77)) {
_global.hit = 2;
_root.mace._visible = true;
_root.sword._visible = false;
Mouse.hide(); }}

//on one of the main frames of the movie
startDrag(“mace”, true);

The sword has similar code but specific to it instead. They both appear when the appropriate keys are struck, but only the first one selected actually drags. If I select the sword first, the mace doesn’t drag and vice versa. Is there any way around this?

p.s. I was trying to get the on(keyPress) command to work but couldn’t figure out how to get it to accept the key codes. When it said there were no errors in the code, it just didn’t work. Any help with this would be appreciated.

Thanks for any help that anyone can give me.

Hi, the art work on the weapons is good. I don’t use startdrag() when I make my games and prefer to use another method. I’ve attached a fla. which was intended to be the first part in a tutorial I was making for a basic first person shooter so I sent the tutorial and files to Kirupa, but I’m not sure if he wants to put it up.

The zip you posted, is that the latest version? I would like to have a look at the latest version of the game, as that’s what I do with flash (games), and although I’m no pro, maybe I could give you some suggestions.

Anyway, here’s the fla.

Also, you could have different weapons, in different frames of the same movie clip instead of using different clip and setting them to visible or invisible. You would change variables depending on the weapons, and refer back to the weapon variable when doing a hitTest, which would determine anything from the amount of blood drawn - to which key press activates it.

Sorry, here’s the second one again. I added another frame of the big gun’s flare - looks smoother - I like to get things right!

This is the newest version of the Yellow Imp game. Everything is working properly in this version with using the on(keyPress “<Left>”) and right commands for weapon switching. The zip is too big to attach so here’s the website you can download it from
(It’s 182 k)

Eventaully, I want to have the sword selection as “s” and mace selection as “m.” What’s the proper way to put in key codes? With the code:
on(keyPress “83”)
with 83 being the listed keycode for “s” but the key that actually activates is 8. I even changed it from 83 to 8 for the keycode value, but when I tested it, 8 was still the key activated. What’s wrong with my syntax?

On keyPress only allows certain keys to be used. You have to use Key.getAscii or Key.getCode if you want to use othe keys. Or you could set up a listener. I will have a look at your game when I get a sec.