Actionscript for shared object doesn't work in seperate .as class

Hi there, bit of an odd problem, I have the following piece of code


var myCookie:SharedObject = SharedObject.getLocal("mySavedData","/")
if(myCookie.data.mySavedText != undefined)
{
var gallerypath:String = myCookie.data.mySavedText;
}

which retrieves a shared data.

If I put this actionscript on the first frame of a new document, it works fine, however I want to use it in something I already have, which uses an external Document class.

Initially it failed to work as I had not included

 import flash.net.SharedObject;

at the beginning, which gave me a few errors like:

1046: Type was not found or was not a compile-time constant: SharedObject.

so I figured that out but now I get

1120: Access of undefined property myCookie.

I am puzzled as to why this should be, as it is clearly defined there, and also why this should not work in a separate document class when it works fine if it is in the actions window of the main project…

Any ideas>?;(