[英]Custom Flex 4 data components won't compile within fx:Declarations tags (and aren't allowed outside them)
我建立了一個擴展的庫來渲染來自多個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聲明行的報告之前似乎指示錯誤, xmllist_test.mxml(-1)
我不知道如何解釋編譯器消息。
我找不到任何有關如何以這種方式使用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編譯是否由於我在語法上出錯而失敗,或者我的誤解是在哲學層面上並且我嘗試了一些尚未實現的事情。
預先感謝您對這個問題可能提出的任何看法。
1)由於MafXMLListCollection沒有實現IVisualElement,因此不能將其包含在可視元素聲明中(因此,需要提供有關標簽的警告)。
2)由於MafXMLListCollection具有構造函數的參數,因此不能使用MXML格式聲明。 您必須在<Script>塊內創建變量:
public var mafSource2:MafXMLListCollection = new MafXMLListCollection(maf);
或者,您可以將MafXMLListCollection更改為具有默認構造函數,並使用metasource屬性(您已經在MXML中進行了此操作)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.