Cleod9 / as3js

An ActionScript to JavaScript transpiler tool built using Node.js
MIT License
141 stars 29 forks source link

i got a type error in the AS3JS Live demo #19

Open Colly001 opened 3 years ago

Colly001 commented 3 years ago

The error is : TypeError: Cannot read properties of undefined(reading 'packageName')

The code i am trying to convert is :

package
{
   import flash.display.Sprite;
   import alternativa.tanks.config.Config;
   import alternativa.tanks.Game;
   import flash.events.Event;
   import alternativa.tanks.GameEvent;
   import flash.display.StageScaleMode;
   import flash.display.StageAlign;
   import flash.display.StageQuality;

   public class TanksTestingTool extends Sprite
   {

      public function TanksTestingTool()
      {
         super();
         stage.scaleMode = StageScaleMode.NO_SCALE;
         stage.align = StageAlign.TOP_LEFT;
         stage.quality = StageQuality.HIGH;
         this.loadConfig("config.xml");
      }

      private var config:Config;

      private var game:Game;

      private function loadConfig(url:String) : void
      {
         this.config = new Config();
         this.config.addEventListener(Event.COMPLETE,this.onConfigLoadingComplete);
         this.config.load(url);
      }

      private function onConfigLoadingComplete(e:Event) : void
      {
         trace("Config loaded");
         this.game = new Game(this.config,stage);
         this.game.addEventListener(GameEvent.INIT_COMPLETE,this.onGameInitComplete);
      }

      private function onGameInitComplete(e:Event) : void
      {
         trace("Game init complete");
         stage.addEventListener(Event.ENTER_FRAME,this.onEnterFrame);
      }

      private function onEnterFrame(e:Event) : void
      {
         this.game.tick();
      }

      private function testMapping(n:int) : void
      {
         var r:* = 0;
         var c:* = 0;
         var m:* = 0;
         var i:* = 0;
         r = 0;
         while(r < n)
         {
            c = r + 1;
            while(c < n)
            {
               m = this.mapping(r,c,n);
               trace(r,c,m);
               if(m != i++)
               {
                  throw new Error();
               }
               else
               {
                  c++;
                  continue;
               }
            }
            r++;
         }
      }

      private function mapping(r:int, c:int, n:int) : int
      {
         return r * (n - 1) - (r * (r + 1) >> 1) + c - 1;
      }
   }
}
Cleod9 commented 3 years ago

Hey, so unfortunately I'm no longer supporting this library so I can't help beyond this, but I can at least tell you that you're receiving that error because the live demo is hard-coded to expect a class named Main to be defined. So you would need to add a stub for Main to the code input text box:

/* AS3JS File */
package
{
   public class Main
   {
   }
}

Note when working with AS3JS outside of the live demo you can define your own entry point name.