PDA

View Full Version : Problem with magnifier



Xoxo
December 28th, 2007, 05:21 PM
Hello everybody!

I'm trying to make an swf with an effect of a magnifier, and I have this code in moveMag.as:


package {
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;


public class moveMag extends MovieClip {

stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMag);

public function moveMag(e:MouseEvent):void {
magnify.x=e.stageX;
magnify.y=e.stageY;
big.x=(small.width/ big.width)-e.stageX-magnify.width/2;
big.y=(small.height/ big.height)-e.stageY-magnify.height/2;
}
}
}

In my fla file I have a mask, and two images (big and small) in different layers.

When I test I get an error: Error 1120 "stage" property not defined

Any ideas for fixing this? Thank you very much!

Felixz
December 29th, 2007, 11:14 AM
u must pullOut that stage sinse it is avaiable after ADDED_TO_STAGE Event just make a listener

notSoMuch
December 29th, 2007, 11:27 AM
u must pullOut that stage sinse it is avaiable after ADDED_TO_STAGE Event just make a listener
He's probably right...he knows everything else!!!

Xoxo
December 29th, 2007, 11:52 AM
Thank you for your quick replay but...


u must pullOut that stage sinse it is avaiable after ADDED_TO_STAGE Event just make a listener

How can I do that? I'm a bit confused... the listener must be applied to an element in the stage... isn't it?

Looking forward your reply.

Felixz
December 31st, 2007, 06:58 AM
package {
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.MouseEvent;
class moveMag extends MovieClip {
public function moveMag() {
this.addEventListener(Event.ADDED_TO_STAGE,init);
}
protected function moveHandler(event:MouseEvent):void {
magnify.x=event.stageX;
magnify.y=event.stageY;
big.x=small.width / big.width - event.stageX - magnify.width / 2;
big.y=small.height / big.height - event.stageY - magnify.height / 2;
}
protected function init(event:Event):void {
this.removeEventListener(Event.ADDED_TO_STAGE,init );
stage.addEventListener(MouseEvent.MOUSE_MOVE,moveH andler);
}
}
}

Xoxo
December 31st, 2007, 07:15 AM
Many many thanks but...


ReferenceError: Error #1065: Haven't defined variable moveMag.

I don't know what's happening.... :ne:

Felixz
December 31st, 2007, 07:42 AM
I have no idea why moveMag is undefined since it is className and constructor are named that.
i think u haven't copied all code

Xoxo
December 31st, 2007, 07:51 AM
Thank you Felixz for your effort and interest. I will look at the files carefully.

Have a nice day!