我已经构建了一个扩展库来呈现来自多个 XML 源的复杂数据,并将其中一些源抽象为仅扩展Object
. 作为一个实验,我开始扩展XMLListCollection
以尝试使数据处理实现更加集成和类似 Flex,但是到目前为止 mxmlc 还没有与有用的消息配合。
产生错误的编译:
(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)
有问题的 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>
我在上面的xmllist_test.mxml
代码中包含了一个可以使用的示例<mx:XMLListCollection>
,但是在我的自定义组件存在时整个编译都失败了<maf:MafXMLListCollection>
。
我不知道如何解释编译器消息,考虑到这xmllist_test.mxml(-1)
似乎表明在计算行数之前出现错误,并且报告了 xml 声明行。
我找不到任何关于如何以fx:Declarations
这种方式使用的文档,尽管它被声明为为非可视组件保留的位置,我的是:
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);
}
}
}
尽管有这个问题,我可以通过<fx:Script>
标签中的 actionscript 使用自定义组件,而不会出现编译错误。我只是不明白 MXML 编译是否因为我犯了句法错误而失败,或者我的误解是在哲学层面上并且我尝试了一些没有实现的东西。
预先感谢您就该主题提供的任何观点。