3 Replies Latest reply on Dec 21, 2007 1:18 PM by Garyl Woolworth

    Transfer variables

    gerraIrkutsk-vtxlyW Level 1
      I put XML file in Application as ArrayCollection and I want to get access for this variable from Component by Application.application. But variable gets there empty. If I try to get in Component other type of variable from Application (example String) all is well. Where I can read about a transfer of variables between Application and Components?
        • 1. Re: Transfer variables
          atta707 Level 2
          should work as you've described. you might want to show some code.

          instead of doing the Application.application to get data from components, better approaches could be 1) exposing a property in the component and setting it from the module that's using it or 2) dispatching an event with data and let the component handle that event to get data.

          ATTA
          • 2. Re: Transfer variables
            gerraIrkutsk-vtxlyW Level 1
            It's my Application - main.mxml
            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
            applicationComplete="{sitallPhoto.send()}"
            xmlns:comp="components.*">
            <mx:Script>
            <![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.collections.ArrayCollection;
            [Bindable]
            public var wData:ArrayCollection;
            private function imageHandler(evt:ResultEvent):void
            {
            wData=evt.result.manybooks.picture;
            }
            ]]>
            </mx:Script>
            <comp:imagePanel id="myComp" />
            <mx:HTTPService id="sitallPhoto" url="assets/pictureBooks.xml" result="imageHandler(event)" />
            </mx:Application>

            It's my Component imagePanel.mxml
            <?xml version="1.0" encoding="utf-8"?>
            <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="250" height="400" backgroundColor="#C0C0C0">
            <mx:Script>
            <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.core.Application;
            [Bindable]
            public var wcData:ArrayCollection=Application.application.wData;
            ]]>
            </mx:Script>
            <mx:DataGrid id="gridInComp" dataProvider="{wcData}"/>
            </mx:Canvas>

            It's XML file pictureBooks.xml
            <?xml version="1.0"?>
            <manybooks>
            <picture>
            <description>Сувенирный набор к юбилею города Черемхово</description>
            <fileName>cheremx.jpg</fileName>
            <filePreview>cheremx_s.jpg</filePreview>
            </picture>
            <picture>
            <description>Подарочный настольный календарь в коробке для компании «Росгосстрах»</description>
            <fileName>kalend1.jpg</fileName>
            <filePreview>kalend1_s.jpg</filePreview>
            </picture>
            <picture>
            <description>Дневники школьников для городов Иркутской области, 2006 – 2007 гг.</description>
            <fileName>P1050082.jpg</fileName>
            <filePreview>P1050082_s.jpg</filePreview>
            </picture>
            <picture>
            <description>Подарочное издание книги «Моя Иркутская область»</description>
            <fileName>P1050083.jpg</fileName>
            <filePreview>P1050083_s.jpg</filePreview>
            </picture>
            <picture>
            <description>Подарочное издание книги «Моя Иркутская область». Подарочный футляр</description>
            <fileName>P1050084.jpg</fileName>
            <filePreview>P1050084_s.jpg</filePreview>
            </picture>
            </manybooks>


            When I try to get wData from Application in Component my Component don't get it's (in my case DataGrid displays nothing)
            • 3. Re: Transfer variables
              Garyl Woolworth Level 1
              I think your problem lies in these lines.

              [Bindable]
              public var wData:ArrayCollection;
              private function imageHandler(evt:ResultEvent):void
              {
              wData=evt.result.manybooks.picture;
              }

              You type casted wData to an ArrayCollection however you've never actually created a new instantiation of it. Try public var wData:ArrayCollection = new ArrayCollection(); and see if that works. If this doesn't fix your problem, it might be that your trying to convert XML straight to an ArrayCollection. I have a limited knowledge of XML seeing as how I normally use database results but ways that I've seen it done have looped over the XML result and add each item 1 by 1.

              The last item I wanted to point out is your datagrid has no columns.

              <mx:DataGrid id="gridInComp" dataProvider="{wcData}"/>

              That's all fine and dandy except that you need to add the columns and reference the dataField's to match the XML identifiers so that Flex knows which items you want to show such as fileName, filePreview, description, etc...

              Hope this helps.