PDA

View Full Version : Error #1034: Type Coercion failed


artus
02-01-2011, 08:11 AM
Hello,

I'm posting a thread because I'm stuck on something...

I am trying to call a function of my main document class from an external swf
but I can't seem to work around this error :
TypeError: Error #1034: Type Coercion failed: cannot convert Dragger_fla::MainTimeline@29e5f121 to Main.
at Dragger_fla::Dragger_1/down()

The code in my main docuemnt class is :
package {

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;

public class Main extends MovieClip {;

public static var stage:Stage;
public static var root:DisplayObject;
public static var tester:String;

public function Main():void {
}
public function Drag_ON():void {
trace("Drag_ON called");
}
}
}

and the code in my external swf is (code is on timeline and not in a seperate class ) :
//
BT.addEventListener(MouseEvent.MOUSE_DOWN, down);
function down(event: MouseEvent) {
//MovieClip(parent.parent.parent.parent.parent.paren t.parent).tout.startDrag()
//Stage.tout.startDrag();
//TopLevel.tester="changed"
//trace(TopLevel.tester)
Main(root).Drag_ON();
}

Does anybody know why I have this error ?

Any help will be appreciated. Thanks.

Imjake9
02-02-2011, 02:50 AM
Seems to me that your error is this code:
Main(root).Drag_ON();
It should be this:
var main:Main = new Main();
main.DRAG_ON();
Unless I'm confusing something here.

Also, this is my first post in a little over a year. Ah it's good to be back!

artus
02-02-2011, 10:11 AM
Hi, and thanks for looking into my problem.

Unfortunately the code you suggest send a different type of error :

Call to a possibly undefined method DRAG_ON through a reference with static type Main.

Imjake9
02-02-2011, 11:19 PM
Oops, I'm sorry, it should be main.Drag_ON(), my bad. But on the other hand, I would think you'd be able to figure that out yourself. (No offense.)

artus
02-03-2011, 07:35 AM
ok, you're right I should have found that out by myself.

Now there's a different problem though :

Error #1009: Cannot access a property or method of a null object reference.
at Main/frame1()