0 Replies Latest reply on Jul 25, 2006 8:08 AM by ExeyPanteleev

    Link to xml from xml (<mx:Button click="function({...});">)

    ExeyPanteleev
      links.xml contains links for page1, page2

      links.xml
      |
      +-- page1.xml
      |
      +-- page2.xml

      I try:
      <mx:Button click="loadXML2({ getField( XML( linksItems.currentItem ), how1Link ) });" label="Link" />

      Debugger says:

      Error: Repeater is not executing.
      at mx.core::Repeater/get currentItem()
      at LinkFromXML2/___LinkButton1_click()



      <!-- File: links.xml -->
      <?xml version="1.0" encoding="UTF-8"?>
      <rdf:RDF xmlns=" http://web.resource.org/cc/"
      xmlns:dc=" http://purl.org/dc/elements/1.1/"
      xmlns:rdf=" http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <item>
      <dc:title>Page 1</dc:title>
      <dc:link>page1.xml</dc:link>
      </item>
      <item>
      <dc:title>Page 2</dc:title>
      <dc:link>page2.xml</dc:link>
      </item>
      </rdf:RDF>

      <!-- File: page1.xml -->
      <?xml version="1.0" encoding="UTF-8"?>
      <rdf:RDF xmlns=" http://web.resource.org/cc/"
      xmlns:dc=" http://purl.org/dc/elements/1.1/"
      xmlns:rdf=" http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <dc:Work>
      <dc:title>Page 1</dc:title>
      </dc:Work>
      </rdf:RDF>

      <!-- File: page2.xml -->
      <?xml version="1.0" encoding="UTF-8"?>
      <rdf:RDF xmlns=" http://web.resource.org/cc/"
      xmlns:dc=" http://purl.org/dc/elements/1.1/"
      xmlns:rdf=" http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <dc:Work>
      <dc:title>Page 2</dc:title>
      </dc:Work>
      </rdf:RDF>

      <!-- File: LinkFromXML.mxml -->

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute" creationComplete="loadXML('links.xml');">
      <mx:Script>
      <![CDATA[
      import mx.collections.XMLListCollection;

      public var pathxml:String;
      public var pathxml2:String;
      private var how:Namespace = new Namespace(" http://web.resource.org/cc/");
      private var dc:Namespace = new Namespace(" http://purl.org/dc/elements/1.1/");
      [Bindable]
      private var how1Title:QName = new QName(dc, "title");
      [Bindable]
      private var how1Link:QName = new QName(dc, "link");
      [Bindable]
      private var how2Title:QName = new QName(dc, "title");
      [Bindable]
      private var how1externalXML:XMLListCollection;
      [Bindable]
      private var how2externalXML:XMLListCollection;

      private function loadXML(pathxml):void {
      trace (pathxml);
      var loader:URLLoader = new URLLoader();
      var request:URLRequest = new URLRequest(pathxml);
      loader.load(request);
      loader.addEventListener(Event.COMPLETE, onComplete);
      }
      private function loadXML2(pathxml2):void {
      var loader2:URLLoader = new URLLoader();
      var request2:URLRequest = new URLRequest(pathxml2);
      loader2.load(request2);
      loader2.addEventListener(Event.COMPLETE, onComplete2);
      }
      private function onComplete(event:Event):void {
      var loader:URLLoader = URLLoader(event.target);
      var how1Items:QName = new QName(how, "item");
      var dataXML:XML = XML( loader.data );
      dataXML.addNamespace( dc );
      var how1base:XMLList = dataXML.descendants( how1Items
      );
      how1externalXML = new XMLListCollection( how1base );
      }
      private function onComplete2(event:Event):void {
      var loader2:URLLoader =
      URLLoader(event.target);
      var how2Items:QName = new QName(dc, "Work");
      var dataXML:XML = XML( loader2.data );
      dataXML.addNamespace( dc );
      var how2base:XMLList = dataXML.descendants( how2Items
      );
      how2externalXML = new XMLListCollection( how2base );
      }
      private function getField( itemXML:XML,
      field:QName):String {
      return itemXML.descendants( field ).toString();
      }
      ]]>
      </mx:Script>
      <mx:Canvas id="HowView" backgroundColor="#FFFFCC" label="How"
      width="100%" height="100%">
      <mx:HBox width="100%" height="100%">
      <mx:VDividedBox width="400" height="100%" id="how1Box"
      backgroundColor="#B9C5A0">
      <mx:Repeater width="80%" id="linksItems"
      dataProvider="{ how1externalXML }">
      <mx:VBox width="80%" horizontalAlign="center"
      creationCompleteEffect="Fade">

      <mx:LinkButton click="loadXML2('{getField( XML( linksItems.currentItem ), how1Link )}')" label="{ getField( XML( linksItems.currentItem ), how1Title) }" />

      </mx:VBox>
      </mx:Repeater>
      </mx:VDividedBox>
      <mx:VDividedBox width="100%" height="100%" id="how2Box"
      backgroundColor="#6BA1A3">
      <mx:Repeater width="100%" id="workItems"
      dataProvider="{ how2externalXML }">
      <mx:VBox width="534" horizontalAlign="center"
      creationCompleteEffect="Fade">

      <mx:Label text="{ getField( XML(
      workItems.currentItem ), how2Title) }" color="#000000"/>

      </mx:VBox>
      </mx:Repeater>
      </mx:VDividedBox>
      </mx:HBox>
      </mx:Canvas>
      </mx:Application>