0

I'm trying to use flash8 to create an drag and drop event using the mouse.

My code is:

import flash.events.MouseEvent;
circle_mc.addEventListener(MouseEvent.MOUSE_DOWN,downf);
circle_mc.addEventListener(MouseEvent.MOUSE_UP,upf);
function downf(e:MouseEvent) { circle_mc.startDrag(); }
function upf(e:MouseEvent) { circle_mc.stopDrag(); }

I get these errors:

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: Statement must appear within on/onClipEvent handler
     circle_mc.addEventListener(MouseEvent.MOUSE_DOWN,downf); 

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 4: Statement must appear within on/onClipEvent handler
     circle_mc.addEventListener(MouseEvent.MOUSE_UP,upf);

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 5: The class or interface 'MouseEvent' could not be loaded.
     function downf(e:MouseEvent) {

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 7: The class or interface 'MouseEvent' could not be loaded.
        function upf(e:MouseEvent) { circle_mc.stopDrag(); }

Total ActionScript Errors: 4     Reported Errors: 4

I don't understand why this is happening. On Internet I've found that this error may be caused due to the version of AS3 or AS2, but I also can't find the version I use.

Any help is appreciated.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40

1 Answers1

0

The code you've posted is clearly AS3 but since you're using Flash 8 you're limited to AS2. No problem though, you can achieve the same using AS2 of course.

  1. Draw a circle using the Oval Tool and select it using the Selection Tool
  2. Hit F8 to convert it to a symbol and hit OK
  3. In the Properties panel give the instance a name e.g. circle_mc
  4. Open the Actions window (F9) and select Scene 1 -> Layer 1 : Frame 1
  5. Paste the following code
circle_mc.onPress = function()
{
    startDrag(this, true);
}
circle_mc.onRelease = function()
{
    this.stopDrag();
}
obscure
  • 11,916
  • 2
  • 17
  • 36