Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8010587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:46:55+00:00 2026-06-04T18:46:55+00:00

I have an array of Widgets (a class I created) called widgetArray that I

  • 0

I have an array of Widgets (a class I created) called “widgetArray” that I save into a shared object.

savedGame1.data.widgetArray = widgetArray;

When I go to load this data out and use the widgets I run into problems. The array is stored fine, but each widget is saved as an object. So I can’t simply do:

widetArray = savedGame1.data.widgetArray;

because then if I try to use the widgets:

widgetArray[0].someWidgetFunction();

it does not work because flash thinks they are objects. I have tried typecasting the widgets when I load them, but it only produces a null object.

widgetArray[i] = widgetArray[i] as Widget;//widgetArray[i] becomes null
tempWidget:Widget = widgetArray[i] as Widget;//null as well

This question is asked in one of the forums from a friend, since there were no responses, i thought this is the right place for it…
How does anyone else deal with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T18:46:57+00:00Added an answer on June 4, 2026 at 6:46 pm

    Make two methods that can save and load a widget, the save method should take the data from the widget class and save it into the shared object the load class will take the data from the shared object and set the properties of the object.

    Something like this :

    public function save():Object
    {
       return {
          "x":this.x,
          "y":this.y,
          "otherStuff":otherStuff
       };
    }
    
    public function load(data:Object):void
    {
      this.x = data.x;
      this.y = data.y;
      this.otherStuff = data.otherStuff;
    }   
    

    You can call the save method and store the results in an array and then store it in the shared object. You only need to save the data that is required to rebuild the widget class, not all the properties of the class.

    Edit : Updated based on BlueRaja’s comment.

    As BlueRaja pointed out IExternalizable is meant to be used for this.

    If you have a class like this :

    public class MyClass implements IExternalizable
    {
        private var one:int = 1;
        private var two:int = 2;
    
        public function MyClass() 
        {
        }
    
        public function writeExternal(output:IDataOutput):void
        {
            output.writeInt(one);
            output.writeInt(two);
        }
    
        public function readExternal(input:IDataInput):void
        {
            one = input.readInt();
            two = input.readInt();
        }
    
        public function print():void
        {
            trace(one);
            trace(two);         
        }
    }
    

    Then you can save it like this:

    registerClassAlias("MyClass", MyClass);
    
    var sharedObject:SharedObject = SharedObject.getLocal("so");
    
    var myClass:MyClass = new MyClass();    
    sharedObject.data['storedObject'] = myClass;    
    sharedObject.flush();
    

    Then to load it :

    registerClassAlias("MyClass", MyClass);
    
    var sharedObject:SharedObject = SharedObject.getLocal("so");
    
    var loadedClass:MyClass = sharedObject.data['storedObject'] as MyClass;
    loadedClass.print();
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView that is created based on an array of items. I
I have a products array of widgets. Some widgets have the reserved period symbol
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
I have array of strings, String[] data and it's 10 elements has value P
I have a widget that currently takes a random string from an array and
For example: I have a User which has 10 Widgets. Along with that I
I have got an app that saves audio on sd card. I've created a
I have a string-array, that i need to display in a layout. The code
I have this widget: $this->setWidget('slug', new sfWidgetFormDoctrineChoice(array('model' => 'MyTable', 'method' => 'myMethod', 'key_method' =>
I have array: array( 0 => new SomeClass(1), 1 => new SomeClass(2), 2 =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.