Thanks, but where can I put the 'addEventListener' ?  
I Put it in init() but I'm getting: 

error: 1119: Access of possibly undefined property bookcategory
through a reference with static type class

on this line:

components.BookCovers.bookcategory.addEventListener(MouseEvent.CLICK,
booksFilterFunc );
 
also is this a CLICK event? do I have the correct event type here?
thanks,


This is BooksMain.mxml:
============================================================================
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
height="100%" width="100%" 
        layout="absolute" backgroundColor="#FFFFFF" xmlns:comp="components.*" 
        creationComplete="init()">
        <mx:Script>
                <![CDATA[
                 import mx.utils.ArrayUtil;
                 import mx.rpc.events.*;
                 import mx.collections.*;
                 import classes.CartEvent;
                 [Bindable]
                 public var books:ArrayCollection;

         public function booksFilterFunc(item:Object):Boolean
          {
             return item.category == bookcategory.selectedItem;
          }
             public function filterbooks(event:Event):void
          {
                books.filterFunction = booksFilterFunc;
                books.refresh();
          }
                 [Bindable]
                 public var purchasedBooks:ArrayCollection = new 
ArrayCollection();
                 private function init():void
                        {
                                                                                
 
components.BookCovers.bookcategory.addEventListener(MouseEvent.CLICK,
booksFilterFunc );

                           bookDataIn.send();
                        }
                 private function bookHandler(event:ResultEvent):void
                        {
                                books = event.result.books.image;
                        }
          private function bookSelectionHandler(event:CartEvent):void
          {
                purchasedBooks.addItem(event.selectedBook);
          }
  
 
                ]]>
        </mx:Script>
<mx:HTTPService id="bookDataIn"
url="http://www.yourasianconnection.com/rss/assets/books.xml";
result="bookHandler(event)"/>
        <mx:Style>
                ComboBox
                {
                        selectionColor:#32cd32
                }
                global
                {
                        color:#00008b
                }
        </mx:Style>
        <mx:Image source="assets/logo1.gif"  x="357" y="10"/>
        <mx:LinkBar dataProvider="bookPages"  x="105" y="151"/>
        <mx:ViewStack id="bookPages" resizeToContent="true" x="118" y="185">
                <comp:BookHome height="50%" width="50%" label="Home" id="home" 
/>
                <comp:BookCovers height="50%" width="50%" label="Our Books"
id="bookCovers" coverData="{books}"   
                        bookSelected="bookSelectionHandler(event)" />
                <comp:Comments height="50%" width="50%" label="Comments"
id="comments" />
        </mx:ViewStack> 
        <comp:BookCart  x="750" y="291" purchasedBooks="{purchasedBooks}" />
</mx:Application>
===============================================================================

This is components/BookCovers.mxml:
===============================================================================
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"; width="500"
  xmlns:components="components.*">
  <mx:Metadata>
        [Event(name="bookSelected", type="classes.CartEvent")]
  </mx:Metadata>
<mx:Script>
        <![CDATA[
                import mx.controls.Alert;
                import mx.collections.ArrayCollection;
                import classes.CartEvent;
                [Bindable]
                public var coverData:ArrayCollection;
                [Bindable]
                public var selectedCover:Object;
                [Bindable]
                public var selectedAuthor:Object;
                [Bindable]
                public var selectedDescription:Object;
                private function displayBookDetails(event:Event):void
                {
                   currentState='coverDetails';
           selectedCover = new Object();
           selectedCover = event.currentTarget.selectedItem;
          
coverState.load('http://www.yourasianconnection.com/rss/assets/' +
selectedCover.filename + '.jpg');
           selectedAuthor = selectedCover.author;
           selectedDescription = selectedCover.desc;
                }
                private function purchaseBook():void
                {
                        var eventObj:CartEvent = new 
CartEvent(selectedCover,"bookSelected");
                        dispatchEvent(eventObj);
                        
                }

        ]]>
</mx:Script>
<mx:states>
   <mx:State name="coverDetails">
         <mx:RemoveChild target="{coverThumbnails}" />
         <mx:AddChild position="lastChild">
                <mx:Canvas >
                        <mx:Image id="coverState" y="35"/>
                        <mx:Button label="Return to Book Covers"
                                click="currentState=''" />
                        <mx:Text y="280" text="{selectedAuthor}"  
fontWeight="bold"
fontSize="18" color="#0080ff" id="author"/>        
                    <mx:Text y="300" text="{selectedDescription}" fontSize="14"
width="400" />
                    <mx:Button label="Add to Cart" y="400" x="200"
click="purchaseBook()" />
                </mx:Canvas>
         </mx:AddChild>
         <mx:SetProperty name="height" value="500"/>
   </mx:State>
        
</mx:states>
        <mx:HBox backgroundColor="#EE82EE" verticalAlign="middle" fontSize="12" 
>
                <mx:Label text="Select the Books:" />
                <mx:CheckBox label="All Books" />
                <mx:Label text="Select Book Category" />
                <mx:ComboBox id="bookcategory" change="filterBooks(event)" >
                        <mx:dataProvider>
                                <mx:ArrayCollection>  
                                        <mx:String>Dreamweaver</mx:String>
                                <mx:String>Flash</mx:String>
                                        <mx:String>Graphics</mx:String>
                                        <mx:String>Web Design</mx:String>
                                        <mx:String>Other</mx:String>
                                </mx:ArrayCollection>
                        </mx:dataProvider>
                </mx:ComboBox>
        </mx:HBox>
        <mx:TileList id="coverThumbnails" dataProvider="{coverData}"
                change="displayBookDetails(event)"
                itemRenderer="components.CoverDisplay"
                width="500" height="400" columnWidth="120" rowHeight="110" />
        
</mx:VBox>
===============================================================================






--- In flexcoders@yahoogroups.com, Sebastian Zarzycki <[EMAIL PROTECTED]> wrote:
>
> 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 ?
> >
>


Reply via email to