Question

I have built an extensive library to render complex data from several XML sources, and have abstracted some of these sources as classes which just extend Object. As an experiment, I began extending XMLListCollection in an attempt to make the data-handling implementation more integrated and Flex-like, but thus far mxmlc does not cooperate with a useful message.

The compilation which generates an error:

(fcsh) mxmlc  -use-network=true -omit-trace-statements=false -debug=true xmllist_test.mxml
fcsh: Assigned 1 as the compile target id
Loading configuration file /dev/Flex SDK/frameworks/flex-config.xml
Recompile: xmllist_test.mxml
Reason: The source file wasn't fully compiled.
Files changed: 0 Files affected: 1
xmllist_test.mxml(-1):  Error: Incorrect number of arguments.  Expected 1.

<?xml version="1.0" encoding="utf-8" ?>

(fcsh) 

The offending mxml, xmllist_test.mxml:

<?xml version="1.0" encoding="utf-8" ?>
<!-- xmllist_test -->
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:mx="library://ns.adobe.com/flex/mx" 
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:maf="mafComponents.*"
creationComplete="makeItSo()"
backgroundColor="#FFFFFF">
<s:layout>
    <s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mafComponents.examples.*;
public var maf:XML = MafExamples.ghp010; // defined statically in the package
public function makeItSo():void
{
    trace('name', maf.@name);
}
]]>
</fx:Script>
<fx:Declarations>
    <!-- a comment -->
    <mx:XMLListCollection id="mafSource1" source="{maf.block}"/> <!-- no problem -->
    <maf:MafXMLListCollection id="mafSource2" metasource="maf}"/> <!-- won't compile -->
</fx:Declarations>
</s:Application>

I included in the above xmllist_test.mxml code an example which works using <mx:XMLListCollection>, but the whole compilation fails at the presence of my custom component <maf:MafXMLListCollection>.

I don't know how to interpret the compiler message, considering that xmllist_test.mxml(-1) seems to indicate an error before lines were counted, and the reporting of the xml declaration line.

I couldn't find any documentation on how to use fx:Declarations in this way, although it is stated as a place reserved for non-visual components, which mine is:

package mafComponents
{
    import mx.collections.*;
    /**
    * An extension of XMLListCollection that specifically serializes the "block" elements of a MAF, while processing other information as well.
    **/
    public class MafXMLListCollection extends XMLListCollection
    {
        public var maf:XML;
        public var mafXMLList:XMLList;
        public var name:String;
        private var _metasource:*;
        /**
        * Process the sequence of "blocks" in datasource to an XMLList to use as the parent class's "source" attribute
        **/
        public function set metasource(datasource:*):void
        {
            // multiple options for source, get it to the point of an XML with "maf" at the root
            if (datasource is XML)
            {
                maf = datasource as XML;
            }

            mafXMLList = maf.block; // this expression returns an XMLList
            name = 'MafXMLListCollection_' + maf.@name;
            source = mafXMLList;

            // do other stuff with the data structure here
            // ...
        }
        /**
         * @private
        **/
        public function get metasource():* { return _metasource; }

        public function MafXMLListCollection(datasource:*)
        {
            super();
            metasource = datasource;

            // make the main list from the sequence of "block" sections in the XML
            trace(name + '.length: ' + length);
        }
    }
}

Despite this problem, I can use the custom component through actionscript in the <fx:Script> tag without compilation errors. I just don't understand if the MXML compilation fails because I am making a syntactic error, or if my misunderstanding is at the philosophical level and I have attempted something that just isn't implemented.

Thank you in advance for any perspective you might offer on the subject.

Was it helpful?

Solution

1) Since MafXMLListCollection doesn't implement IVisualElement, it can't be included in the visual element declaration (hence the warning about the tag being required).

2) Since MafXMLListCollection has parameters to the constructor, you can't use the MXML format declaration. You must create the variable inside your <Script> block:

public var mafSource2:MafXMLListCollection = new MafXMLListCollection(maf);

Or, you could change MafXMLListCollection to have a default constructor, and use the metasource property (which you're already doing in the MXML).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top