nastaseion
nastaseion

Reputation: 173

Error with loader.dataFormat

So I have a class that should send data to an external php file.

Here is my code:

package {

    import flash.display.Sprite;
    import flash.display.DisplayObject;
    import flash.display.Loader;
    import flash.system.Security;
    import flash.system.Capabilities;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    import flash.net.URLLoaderDataFormat;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.AsyncErrorEvent;
    import flash.events.SecurityErrorEvent;

    public dynamic class myClass extends Sprite {

        public static function showAd(mainParent:Sprite, devId:int, adWidth:int, adHeight:int, posX:int, posY:int):myClass {

                var vars:URLVariables = new URLVariables();

                vars["sandboxType"] = Security.sandboxType;
                vars["ver"] = Capabilities.version;
                vars["devid"] = devId;

            // Init connection to the server 

                var zadsReq:URLRequest = new URLRequest("http://...");
                zadsReq.contentType = "application/x-www-form-urlencoded";
                zadsReq.method = URLRequestMethod.POST;
                zadsReq.data = vars;

                var loader:Loader = new Loader();
                loader.dataFormat = URLLoaderDataFormat.TEXT;
                self.addChild(loader);

                loader.addEventListener(Event.COMPLETE, dataLoaded1);
                loader.load(zadsReq);

            return self;
        }

        public static function dataLoaded1(evt:Event):void {

            trace('ok');
        }

    }

}

But I get this error:

1119: Access of possibly undefined property dataFormat through a reference with static type flash.display:Loader.

As you can see, I have already imported flash.net.URLLoaderDataFormat. So what could be the issue here?

Upvotes: 1

Views: 231

Answers (1)

Brian Driscoll
Brian Driscoll

Reputation: 19635

The issue is that you are using a Loader object when what you need is URLLoader. For your reference, Loader is used to load local files (swf, gif, jpg, etc).

So, change the relevant part of your code to use a URLLoader rather than just Loader:

            var loader:URLLoader = new URLLoader();
            loader.dataFormat = URLLoaderDataFormat.TEXT;

            loader.addEventListener(Event.COMPLETE, dataLoaded1);
            loader.load(zadsReq);

Upvotes: 1

Related Questions