Reputation: 73
Pretty new to AS3, still trying to get this to work. Getting a 1061 error when doing this.
Here's the code I have on the .fla file:
import ResizableBox;
var resizeBox:ResizableBox = new ResizableBox();
ResizableBox.startResize();
And then in the file named ResizableBox.as, here's the code for that:
package{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class ResizableBox extends MovieClip{
public function ResizableBox(){
addEventListener(MouseEvent.MOUSE_DOWN, startResize);
}
private function startResize(e:MouseEvent):void{
stage.addEventListener(MouseEvent.MOUSE_MOVE, handleResize);
stage.addEventListener(MouseEvent.MOUSE_UP, stopResize);
}
private function stopResize(e:MouseEvent):void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleResize);
stage.removeEventListener(MouseEvent.MOUSE_UP, stopResize);
}
private function handleResize(e:MouseEvent):void{
this.scaleY = 1
this.height = this.mouseY
}
}
}
I don't know why I'm getting the error. I've also tried adding a static component to the public function, but then I get a 1026 error (Constructor functions must be instance methods). I've looked for what I've been doing wrong, but I can't figure it out.
I also have the source path set properly to the folder containing the .as file.
Any help is greatly appreciated!
EDIT:
Changed ResizableBox.startResize(); to resizeBox.startResize(null);
Changed startResize function from private for public.
Now when I run the thing, I get no errors, until I move to the frame with this code.
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::MovieClip@1ddcc6a1 to ResizableBox.
at flash.display::MovieClip/gotoAndStop()
at CubeTotem_Test_fla::MainTimeline/goSettings()[CubeTotem_Test_fla.MainTimeline::frame1:27]
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ResizableBox/startResize()[C:\Users\Ecco T1\Documents\ResizableBox.as:12]
at CubeTotem_Test_fla::MainTimeline/frame6()[CubeTotem_Test_fla.MainTimeline::frame6:20]
at flash.display::MovieClip/gotoAndStop()
at CubeTotem_Test_fla::MainTimeline/goSettings()[CubeTotem_Test_fla.MainTimeline::frame1:27]
I'm trying to get a simple square to be scaled win the Y direction when clicked and dragged.
FINAL EDIT: Got it to work! I had to convert the box to a symbol and tick "Export to Actionscript" and give it the proper class label. Now I just need to move it from the top-left corner because it doesn't show up on the stage unless I play the animation
Upvotes: 0
Views: 148
Reputation: 26
In the .fla, replace:
ResizableBox.startResize();
with
resizeBox.startResize(null);
Explanation:
startResize() is coded to take one parameter (a MouseEvent object). Your are calling it without giving it a parameter. Calling it with a null reference might not be best practice, but you can do that.
You are trying to call that method on your ResizableBox class (it is not a static method, so it doesn't find it). You need to call the method on the object you created (i.e. resizeBox).
Hope this solves your problem.
*EDIT1: You said it works fine until you "move to the frame with this code". Is "this code" the code you wrote in the question? Or is it another piece of code?
*EDIT2: Oh, how I hate remote debugging... Try adding this.addChild(resizeBox);
and delete the resizeBox.startResize(null);
line (or just comment it)
*EDIT3: I think you might be doing something wrong there. Could you post the code from the goSettings
method?
*EDIT4: So the initial code you posted is from frame 6. Can you post the whole code from that frame?
Upvotes: 1
Reputation: 1263
Make your startResize
method of ResizableBox
public..
public function startResize(e:MouseEvent):void{
Then in fla file, call the method from object..
var resizeBox:ResizableBox = new ResizableBox();
resizeBox.startResize(null);
Upvotes: 0