2 Replies Latest reply on Mar 1, 2007 10:45 AM by ogre11

    instance variables in objects retain values from previously created instances

    ogre11 Level 1
      this makes no f-ing sense and I want to cry.

      I have a class called Note, it receives some text, makes a movie clip makes a textfield on the clip and shows it.

      Each instance can receive text any number of times and itll keep the text in an array and when it comes time to show the note, it arranges the text fields in line under each other.

      the array that holds the text is an instance variable. Now, when I have 2 or more notes in the same movie, the array for each instance RETAINS the text from the previous notes! WTF.

      I do not at any time insert the previous notes' text into the current note, nor is the text array static, those would be the only two logical explanations, nor are the variables of the two notes the same when I create them in the movie.

      here's code

      //creation of the first note on frame 37 of the movie
      var noteNote:Note = new Note(this, _root.movie, 650, 50);
      noteNote.addText("<b>Securities</b>Source provides online access to the most sought-after Canadian and U.S. securities law materials – all in one place – through a single password.");

      //creation of the second note on frame 73 of the movie
      var noteNote2:Note = new Note(this, _root.movie, 650, note.y + note._height);
      noteNote2.addText("As the official publisher, Thomson Carswell’s OSC Bulletin is available weekly by noon each Friday and contains the full weekly Insider Reporting data (Chapter 7) directly from CDS.");

      public var note:MovieClip;
      public var movie:Movie;
      public var x:Number;
      public var y:Number;
      public var parent:MovieClip;
      public var parentMovie:Movie;
      public var fadeDir:Number = 0;
      public var fadeSpeed:Number = 8;
      public static var width:Number = 260;
      private var texts:Array = new Array(); //THIS IS THE ARRAY FOR THE TEXT BLURBS
      public static var buffer:Number = 15;
      public static var color:Number = 0xf9de80;
      public var _height:Number;


      ///text should be one paragraph or one point
      ///if isPoint is left undefined it is assumed false
      public function addText(text:String, isPoint:Boolean):Void
      texts = new Array();
      isPoint = isPoint == undefined ? false : true;
      var index:Number = texts.length;
      texts[index] = [];
      texts[index][1] = isPoint;
      //var textParent:MovieClip = note.createEmptyMovieClip("text_parent_" + note.getNextHighestDepth(), note.getNextHighestDepth());
      var tf:TextField = note.createTextField("text_" + note.getNextHighestDepth(), note.getNextHighestDepth(), buffer, 0, width - ((buffer * 2)), 1000);
      tf.wordWrap = true;
      tf.multiline = true;
      //tf.embedFonts = true;
      tf.background = true;
      tf.backgroundColor = 0xffffff;
      tf.html = true;
      tf.type = "dynamic";
      tf.htmlText = text;
      tf.autoSize = true;
      tf._visible = false;
      texts[index][0] = tf;
      var f:Array = texts;
      I set f to texts every time text is added so I can see texts as a local in the debugger, this is how I found out that the array still kept the text from the Note on frame 37 when making the note on frame 73.

      I've solved this by clearing the array before I first use it in a note, but this still makes no sense, that instance variables are retaining the values of previous instances.

      I'd like some input on what this could be.