Search code examples
actionscript-3classurlloader

as3 how to use a URLLoader in a class


Is it possible to use a URLLoader in a class?

I am trying to use it in a class. Code is taken from: http://www.republicofcode.com/tutorials/flash/as3externaltext/

And here is my class I am trying to use it in but I get this error: C:\Users\com\defaultVars.as, Line 36 1046: Type was not found or was not a compile-time constant: Event.**

package com {
import flash.display.Stage;
import flash.*;

    public class defaultVars
    {



        // loader
        public var myTextLoader:URLLoader = new URLLoader();

        public function defaultVars() 
        {


            myTextLoader.addEventListener(Event.COMPLETE, onLoaded);

                    myTextLoader.load(new URLRequest("myText.txt"));
        }

      public function sampleFunction()
      {
         // trace("not used");
      }




/// ERROR LINE right below. But even if I fix this I get more errors.
function onLoaded(e:Event):void {
trace(e.target.data);
}

////////////////////////

    }

}

Solution

  • try adding this to the top of your file.

    import flash.events.*
    import flash.net.*;