This does not work this way.
First time you are trying to access method that is not know in this file
(object). You cannot execute methods that are defined elsewhere, as
there isn't such thing as global declaration.
Second time you are trying to access method from proper file (object),
but in static way. To access the method, the object first must be create
(of type BooksMain), and the reference to this object
must be known in the file (object) you are going to use it in.
This works quite well other way around, when you want to execute a
method of BookCove from BooksMain (assuming that BooksMain has the
instance of BookCove within), then it will look like this :
BooksMain.mxml :
var cove:BookCove;
cove.execItsMethod();
The proper way to handle the situation you have is to use events. In the
main file (BooksMain) you need to register for event (listen for event
of specific object) :
BooksMain.mxml :
public function methodNameInBookMain(event:Event) {
// do my logic here
}
cove.addEventListener ("EVENT_STRING", methodNameInBookMain);
and then in BookCove dispatch such Event (EVENT_STRING) whenever you
want to inform BookMain that something happened and it has to deal with
that.
BookCove.mxml
dispatchEvent(new Event("EVENT_STRING"));
Keep in mind that Event could be your new object (class) like BookEvent,
and it can have it's own fields, hence be a container for data you want
to use in BooksMain. It's like passing an event (command) with fields as
properites, instead of
executinga method (command) and passing parameters there. It could then
look like this :
dispatchEvent(new BookEvent("EVENT_BOOKEVENT", bookName, bookYear,
bookAuthor));
Dig in documentation for details.
Seb
In BooksMain.mxml I have defined a public function 'filterbooks'
In components/BookCove
rs.mxml I have:
<mx:ComboBox id="bookcategory" change="filterbooks()">
I get error:
1180: Call to a possibly undefined method filterbooks.
if I change it to:
<mx:ComboBox id="bookcategory" change="BooksMain.filterbooks()">
and I get error:
1061: Call to a possibly undefined method filterbooks through a
reference with static type Class.
What's the proper way to reference it ?