all groups > flash (macromedia) > july 2004 >
You're in the

flash (macromedia)

group:

Actionscript: Custom class function call problem


Actionscript: Custom class function call problem aaron NO[at]SPAM unknownerror.com
7/31/2004 11:40:11 PM
flash (macromedia):
Hello,
In short, is it possible to create a custom class with a data
structure and a couple of functions that can be later referred to
after being loaded from disk via SharedObject?

-- The detailed question --
I'm relatively new to the OO in ActionScript so please bare with me.
I've created a program that has a few custom classes I've made using
separate .as files for each class. I've been using these without too
many problems until recently. It's now apparent that I need to start
saving some persistent data using the local SharedObject capabilities
that MX provides.

I'm struggling with the objects that I get back from the SharedObject.
It seems that I cannot refer to any of the custom classes functions
once they've been saved to disk with the SharedObject. For instance,
I have a getName() function in custom class called Player. If I refer
to so.data.player.getName() after I've pulled it out of the
so.data.player object I get undefined back. If I refer to the name
var directly in the player object like so.data.player.name I get the
expected output.

Either my custom class functions get stripped away when the Player
object is saved in the SharedObject (Limitation of what can be saved
to the SO?) or I'm doing something wrong when I create my custom class
(although it works outside of the SO). Perhaps I have to cast the
Object passed back from the SO before I try to run it's specific
functions, (if so, then how do I cast the object to my custom class)?

I can post code but didn't want to add to an already long message.

Thanks,
Re: Actionscript: Custom class function call problem Adam Albright
8/1/2004 8:09:09 AM
[quoted text, click to view]

The short answer is yes. While I've had no need yet to get into custom
classes I picked up a copy of O'Reilly's excellent "ActionScript
Cookbook" which has around 200 pages on the general topic you're
interested in plus about 600 additional pages of other ActionScript
receipes.

It may be worth at least thumbing through this book at your local book
store to see if it answers your more specific questions. The author
has a nice writing style and explains ActionScript with a minimum of
technobable. The author takes you step by step building several custom
applications in the last section of the book using the modular
approach and seperate .as files for several of the projects.

Re: Actionscript: Custom class function call problem aaron NO[at]SPAM unknownerror.com
8/1/2004 12:55:46 PM
[quoted text, click to view]

Adam,
Thank you. Defiantly a book worth picking up. Turns out I was not
registering my classes properly. So Flash didn't know what to type
cast them to. (Object.registerClass("PlayerID", Player);) Explained
in Recipe 16.2.
Thanks again,
AddThis Social Bookmark Button