Skip to main content
Inspiring
April 11, 2012
Question

item showing up as null persistence

  • April 11, 2012
  • 5 replies
  • 663 views

I have a rather hard situation trying to debug this below. When I trace currentNote it shows up as null. I am certain I have notes in the array, because if i leave off  as Note

in the code below I get an error telling me it cannot convert Object to a Note. I think it has something to do with the persistenceManager and how it is converting the array to an Object when I save it, but I make sure to put as Array when getting it out of the Persistence Manager.

Been struggling with this for hours

var currentNote:Note;

pm = new PersistenceManager();

pm.load();

private function getRandomNote():void{

      //This stored array holds up to 4 arrays -- multidemensional

        var theSelectedNotesArray:Array = pm.getProperty("selectedNotesArr") as Array;

         trace(theSelectedNotesArray);

         var randomArray:int = Math.floor(Math.random()*theSelectedNotesArray.length);

         currentNoteArray = theSelectedNotesArray[randomArray];

        trace(currenNoteArray.length) // 52 which is correct

          var randomIndex:int = Math.floor(Math.random()*currentNoteArray.length);

          currentNote = currentNoteArray[randomIndex] as Note;

           trace(currentNote);

}

This topic has been closed for replies.

5 replies

Colin Holgate
Inspiring
April 11, 2012

What does Note extend?

Inspiring
April 11, 2012

It does not extend anything. Here is the class.

package

{

   

    import spark.components.Button;

    public class Note

    {

        var imageUrl:String = "";

        var numWrong:int;

        var numCorrect:int;

        var theCorrectButton:Button;

        public function Note(url:String,button:Button)

        {

            numWrong = 0;

            numCorrect = 0;

            imageUrl = url

            theCorrectButton = button;

        }

       

        public function incrementCorrect():void{

            numCorrect++;

        }

       

        public function incrementWrong():void{

            numWrong++;

        }

       

        public function resetScores():void{

            numWrong = 0;

            numCorrect = 0;

        }

       

        public function getImageURL():String{

            return this.imageUrl;

        }

       

        public function getCorrectButton():Button{

            return theCorrectButton;

        }

    }

}

Colin Holgate
Inspiring
April 11, 2012

By saying trace(note) you're saying that Note has a toString method, but it does't extend anything that has a toString method. What happens if you trace(currentNote.getImageURL)?