Skip to main content
Inspiring
July 18, 2011
Answered

Undefined Function !?

  • July 18, 2011
  • 2 replies
  • 1021 views

Hello everyone !
First I'll give the code I am having the problem about :

import flash.events.MouseEvent; stop() start_btn.addEventListener(MouseEvent.CLICK, startclicked); function startclicked(e:MouseEvent):void {     gotoAndStop(10) } object1.addEventListener(MouseEvent.MOUSE_OVER, overobject1) object2.addEventListener(MouseEvent.MOUSE_OVER, overobject2) object3.addEventListener(MouseEvent.MOUSE_OVER, overobject3) function overobject1(e:MouseEvent):void {     moveobject1(); } function overobject2(e:MouseEvent):void {     moveobject2(); } function overobject3(e:MouseEvent):void {     moveobject3(); } this.stage.addEventListener(Event.ENTER_FRAME, moveMyObjects); function moveMyObjects(event:Event):void {     function moveobject1() {     object1.x -= (object1.x - mouseX) / 3;     object1.y -= (object1.y - mouseY) / 3;     }     function moveobject2() {     object2.x -= (object2.x - mouseX) / 3;     object2.y -= (object2.y - mouseY) / 3;     }     function moveobject3() {     object3.x -= (object3.x - mouseX) / 3;     object3.y -= (object3.y - mouseY) / 3;     } }

The idea is so when I move my mouse over any of these objects they start to follow the pointer.
I get these errors below :

Scene 1, Layer 'Actions', Frame 1, Line 14     1180: Call to a possibly undefined method moveobject1.
Scene 1, Layer 'Actions', Frame 1, Line 17     1180: Call to a possibly undefined method moveobject2.
Scene 1, Layer 'Actions', Frame 1, Line 20     1180: Call to a possibly undefined method moveobject3.                           

Haven't I defined the methods in moveMyObjects function ?
Can anyone help me to achieve the idea this way (with the corrected code) or an other way ( maybe using an array )
Thanks in advance.

This topic has been closed for replies.
Correct answer Ned Murphy

They're not buttons, I have 3 MovieClips on stage.

Think of this as an magnetic attraction .. so my mouse goes near to(or is over) of one of these movieclips ...What it does is it attracts the movieclip until I exit my application(in this case). It is going to do the same with the two other movieClips ..while attracting one of the movieclips for the example, when I mouse_over the other movieClip it attracts it too.


MovieClips, buttons, no matter...  try this and tell me what it doesn't do that you want done...

object1.addEventListener(MouseEvent.MOUSE_OVER, overobject)
object2.addEventListener(MouseEvent.MOUSE_OVER, overobject)
object3.addEventListener(MouseEvent.MOUSE_OVER, overobject)

function overobject(e:MouseEvent):void {
    e.currentTarget.addEventListener(Event.ENTER_FRAME, moveMyObject);
}

function moveMyObject(event:Event):void {
    event.currentTarget.x -= (event.currentTarget.x - mouseX) / 3;
    event.currentTarget.y -= (event.currentTarget.y - mouseY) / 3;
}

2 replies

Ned Murphy
Legend
July 18, 2011

Here's a rewrite that eliminates most of what you have...

stop()

 
start_btn.addEventListener(MouseEvent.CLICK, startclicked);

function startclicked(e:MouseEvent):void {
    gotoAndStop(10)
}

 
object1.addEventListener(MouseEvent.MOUSE_OVER, overobject)
object2.addEventListener(MouseEvent.MOUSE_OVER, overobject)
object3.addEventListener(MouseEvent.MOUSE_OVER, overobject)

function overobject(e:MouseEvent):void {
       e.currentTarget.x -= (e.currentTarget.x - mouseX) / 3;
       e.currentTarget.y -= (e.currentTarget - mouseY) / 3;
}

Ned Murphy
Legend
July 18, 2011

No you have not defined your functions.  Never nest named functions.

he11f1reAuthor
Inspiring
July 18, 2011

I understand ..I wanted to keep trigger the functions with both the ENTER_FRAME and MOUSE_OVER ..do you know how can I fix this situation?

Ned Murphy
Legend
July 18, 2011

Explain what you want the code to do.