David Biga
David Biga

Reputation: 2801

issue with sharedobject in actionscript3

So I am trying to store and load data but for somereason I get error code 1046 - type was not found or was not a comile-time constant and 1120 - access of undefined property SharedObject.

I have imported the right files needed.

This code is in a frame on a timeline and should run once the person clicks on the page that is corresponding with the code.

Code:

import flash.desktop.NativeApplication;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.utils.setInterval;
           // Listen for exiting event.
           NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExit);

           // Also save every 30 seconds.
           setInterval(save, 30*1000);

          // Load data.
           load();


         function onExit(e:Event):void
        {
           save();

        }

        function save():void
        {
                    // Get the shared object.
      var so:SharedObject = SharedObject.getLocal("myApp");

      // Update the age variable.
      so.data['age'] = int(so.data['age']) + 1;

      // And flush our changes.
      so.flush();

      // Also, indicate the value for debugging.
      trace("Saved generation " + so.data['age']);
        }

         function load():void
        {
            // Get the shared object.
      var so:SharedObject = SharedObject.getLocal("myApp");

      // And indicate the value for debugging.
      trace("Loaded generation " + so.data['age']);
        }

Upvotes: 0

Views: 287

Answers (1)

Vesper
Vesper

Reputation: 18747

As usual, this error means you haven't imported the class definition. Add this to the import section of your AS file:

import flash.net.SharedObject;

Upvotes: 2

Related Questions