Skip to main content
Participant
July 7, 2006
Question

Collection with ActionScript 2.0

  • July 7, 2006
  • 1 reply
  • 213 views
I try to use a collection under actionscript 2.0, but my code seems not work...
This is my script for the .fla:

*************************************************
import mx.utils.*;

var mylib:MyLibrary;

myBook = new MyBooks();
myBook.Author = "roger";
myBook.Title = "flash";

mylib.myBooks.addItem(myBook);

trace ("Collection size: " + mylib.myBooks.getLength());
*****************************************************************



and this one for the .as':
**********************************************************************
*** MyLibrary ***
**********************************************************************
import mx.utils.*;

class MyLibrary extends mx.core.UIObject
{
[Collection(name="My Books",variable="myBooks",collectionClass="mx.utils.CollectionImpl", collectionItem="Books", identifier="Title")]
public var myBooks:Collection;
}
********************************************************************************************************


**********************************************
*** MyBooks.as ***
**********************************************
class MesLivres{
[Inspectable(type="String", defaultValue="Title")]
var titre:String;
[Inspectable(type="String", defaultValue="Author")]
var auteur:String;
}
**********************************************************


The response is invariably:
"Collection size: undefined"


Does nobody have an idea ????

Thanks.
This topic has been closed for replies.

1 reply

Inspiring
July 7, 2006
Do you have a copy of the UtilsClasses in your library?
Inspiring
July 7, 2006
Seems to me this parameter:
collectionItem="Books"
should be:
collectionItem="MesLivres"