Flex 4. Transferring data from the main application to the user component

I did not find what I want elsewhere, or at least not enough to adapt

I am trying to create a project that shows radio stations with a logo, a listen button, etc.

The data source is an xml file with child tags, for example, "name", "image" and "listen" for each parent, "station". I access this data through the main application using createComplete = "radioService.send ()" Then I can use it in the main application through dataProvider = "{radioService.lastResult.stations.station}

However, I want to use the results to populate the variables in the user component as in the components themselves

hardcoded examples

mx: Image source = "Images / BBC5.gif" id = "bbc5Logo" "/">

mx: LinkButton id = "bbc5Listen" click = "bbc5Listen_clickHandler (event)" / ">

and in the click handler

protected function bbc5Listen_clickHandler (event: MouseEvent): void {

var url: String = "http://www.bbc.co.uk/iplayer/console/bbc_radio_five_live"; Request var: URLRequest = new URLRequest (url);

} Any help greatly appreciated

+3
source share
5 answers

- , , , , Datagrid . , ( img XML, xpath ), datagrid .

, , , , , DataSource DataSource, XML. DataSource String, .

,

0

Value XML , XML, , - XML, , , JSON.

Value , , , imageSource, id, url ..... Value

-, XML, ArrayCollections of ValueObjets ..

http://www.adobe.com/devnet/flex/videotraining.html

0

:

  • xml [Bindable] actionscript ( , ) (, RadioChannel.class) dataProvider . itemRenderer RadioChannel data getter/setter:

RadioChannel.as:

[Bindable]
public class RadioChannel {

    private var _name: String;
    private var _imageUrl: String;
    private var _listenUrl: String; 

    public function RadioChannel()
    {
    }

    public function get name():String {return _name;}
    public function set name(value:String):void {_name = value;}

    public function get imageUrl():String {return _imageUrl;}
    public function set imageUrl(value:String):void {_imageUrl = value;}

    public function get listenUrl():String {return _listenUrl;}
    public function set listenUrl(value:String):void {_listenUrl = value;}

    public function toString():String
    {
        return 'RadioChannel ' + name + ' - image: ' + imageUrl + 
            ' | listen at ' + listenUrl;

    }
}

RadioList.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:DataGrid xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:mx="library://ns.adobe.com/flex/mx" dataProvider="{radioChannels}">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            private var _radioChannels:ArrayCollection = new ArrayCollection();
            [Bindable]
            private function get radioChannels():ArrayCollection {return _radioChannels;}
            private function set radioChannels(value:ArrayCollection):void {_radioChannels = value;}

        ]]>
    </fx:Script>
    <mx:columns>
        <mx:DataGridColumn>
            <mx:itemRenderer>
                <fx:Component>
                    <mx:Image source="{data.imageUrl}">
                        <fx:Script>
                            <![CDATA[

                                public override function set data(value:Object):void
                                {
                                    super.data = value;
                                    trace('current instance: ' + RadioChannel(data).toString());
                                }

                            ]]>
                        </fx:Script>
                    </mx:Image>
                </fx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
        <mx:DataGridColumn dataField="name" />
        <mx:DataGridColumn>
            <mx:itemRenderer>
                <fx:Component>
                    <mx:HBox>
                        <fx:Script>
                            <![CDATA[
                                protected function onLinkClicked(event:MouseEvent):void
                                {
                                    var currentChannel:RadioChannel = RadioChannel(data);
                                    if (data)
                                    {
                                        var request:URLRequest = new URLRequest(currentChannel.listenUrl);
                                        [...]
                                    }
                                }

                            ]]>
                        </fx:Script>
                        <mx:Button click="onLinkClicked(event)" label="Listen" />
                    </mx:HBox>
                </fx:Component>
            </mx:itemRenderer>
        </mx:DataGridColumn>
    </mx:columns>
</mx:DataGrid>
  • , : url . , .

, click .

, .

0
source

I think it might be useful to pass the value from mainApp to the user component, you can follow this method. Since you have a value in mainApp, in the user component you can access the value using the parentDocument object.parentDocument.rootAppVar

0
source

Source: https://habr.com/ru/post/1769789/


All Articles