0 Replies Latest reply on Jun 6, 2007 6:11 AM by Jonah01

    datamodel help


      I am newbie to flex and was wondering if someone could answer this question for me.

      I have a ActionScipt class called Gift representing a Gift obviously. Standard fields name, description etc.

      I get this data from an xml file using an HttpService request.

      This is all fine.

      I then display this data in a TileList. This is also fine.

      <mx:HTTPService id="srv" url="data/gift.xml"/>
      <mx:TileList id="giftlist" change="this.currentState='GiftDetails'" dataProvider="{srv.lastResult.gifts.gift}" itemRenderer="gifts.GiftThumbnail" alpha="1.0" backgroundAlpha="0.1" borderStyle="none" left="0" right="0" bottom="0" top="0"></mx:TileList>

      I have another component which is used for when you click on a Gift. It will display more details.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">
      private var _gift:Object;

      public function get gift():Object
      return _gift;

      public function set gift(g:Object):void
      _gift = g;


      I pass the data into this component like so

      <ns2:GiftDetails x="0" y="0" width="654" height="451" gift="{giftlist.selectedItem}">

      My question is how can i make sure the TileList knows it contains Gift objects and not just Objects. If i try to cast in the details component it throws an error which means the type in the list is not a Gift. Although i can still access the Gift fields even though they are of type Object. e.g. gift.name etc.

      giftlist.selectedItem is always of type Object when really i should be able to cast this to type Gift.

      Do i need to use a datamodel in some way?

      Any help would be appreciated.