Skip to main content
Adrien_
Known Participant
June 4, 2011
Question

am I passing and handeling vectors wrong?

  • June 4, 2011
  • 2 replies
  • 3198 views

So I have the code of two classes (I can't post any actual code as its way too long - even broken up But I can give you a sample of simmilar aspects)

public class ClassA

{

     private var objectString:Vector.<String>; // create a new vector to hold items - this will be passed

     private var cb:ClassB = new ClassB();

     public function populateVector():void

     {

          objectString.push("hello");

          cb.passVector(objectString); //curently contains "hello."

     }

}

public class ClassB

{

     private var objectContainer:Vector.<String>; //to conain the passed array.

     public function getVector(vectorObject:Vector.<String>):void

     {

          objectContainer = vectorObject; //get the vector passed in and assign its contents to this vector.

     }

     public function passVector():Vector.<String>

     {

          return objectContainer; //return the vector to now pass to another class ClassC

     }

}

public class ClassC

{

     private var getVector:Vector.<String>;

     private var cb:ClassB = new ClassB();

     public function ClassC()

     {

          getVector = cb.passVector();

          trace(getVector)   //In theory - show me hello

     }

}

Yes I have an understanding of vectors so pointing me to the documentation may be worthless. As I have read it hundred times. I would not be posting here if I didnt. How ever I may have missed something.

Upon debugging this I see that Class A has a vector that now contains one element -> "hello." When I pass that vector on Object container is null. Whats worse is now I return a null vector list and pass on a null vector list and trace should in theory show me null.

Why is this happening? In java this is how I would pass vectors and arrays around and I believe some one showed me this is how you do it in actionscript.

Apparently I am wrong in AS. How do I pass vectors around?

If my code contains spelling mistakes or syntax errors I appoligize as I typed this here.

This topic has been closed for replies.

2 replies

Adrien_
Adrien_Author
Known Participant
June 5, 2011

post -- ignore this

kglad
Community Expert
Community Expert
June 4, 2011

use:


public class ClassA
{
     private var objectString:Vector.<String>; // create a new vector to hold items - this will be passed

     private var cb:ClassB = new ClassB();

     public function populateVector():void
     {
          objectString.push("hello");
          cb.getVector(objectString); //curently contains "hello."
     }
}

public class ClassB
{
     private var objectContainer:Vector.<String>; //to conain the passed array.

     public function getVector(vectorObject:Vector.<String>):void
     {
          objectContainer = vectorObject; //get the vector passed in and assign its contents to this vector.
     }

     public function passVector():Vector.<String>
     {
          return objectContainer; //return the vector to now pass to another class ClassC
     }
}

public class ClassC
{
     private var getVector:Vector.<String>;
     private var cb:ClassB = new ClassB();

     public function ClassC()
     {
          getVector = cb.passVector();
          trace(getVector)   //In theory - show me hello
     }
}


Adrien_
Adrien_Author
Known Participant
June 4, 2011

Oh no no. Sorry thats what I mean I get the vector. Ok. So I get the vector, but upon assigning that vector as you see in getVector() thats where the nulls start.

So that vectorObject is now null.

and then passing it means I am passing a null vector. Which continues down the line untill it traces null.

That whole objectConainter = vectorObject -> vectorObject in the debug output pannel under variables is set to null.

This is my issue

Edit: I edited the OP to properly demonstrate the sample code. - Apparently I can't edit my sample Code. it should be getVector not passVector in Class A

kglad
Community Expert
Community Expert
June 4, 2011

copy and paste the relevant lines of code.