[haXe] MovieClip tutorial and package

Marc-Andre Lafortune haxe at marc-andre.ca
Mon Jul 2 23:14:22 CEST 2007


Sorry for the really basic question, but I'm trying to modify the  
example in the MovieClip tutorial http://haxe.org/tutos/extend_mclip  
so that MyClass becomes some_path.MyClass

Before I start, I remove the "-swf-lib lib.swf" from the hxml since I  
don't need any asset. Cool, this works.

Here's what I've done:

1) I move MyClass.as into a folder, say "some_path".

2) I insert "package some_path;" as the first line of MyClass.hx

3) I change "-main MyClass" to "-main some_path.MyClass"

I now get a bad cast error. What's going on?


Just to be sure: resulting files:


-- file some_path/MyClass.hx

package some_path;	// only modification is this line
class MyClass extends flash.MovieClip {

     public function new() {
          trace("created");
     }

     public function draw() {
          beginFill(0xFF0000,50);
          lineTo(50,0);
          lineTo(50,50);
          lineTo(0,50);
          endFill();
     }

     static function main() {
          // create an instance
          var parent = flash.Lib.current;
          var m = cast(parent.attachMovie("MyClass","instance", 
0),MyClass);
          m.draw();
     }
}

-- file test.hxml
-swf test.swf
-swf-version 8
-main some_path.MyClass



More information about the Haxe mailing list