类上存在静态变量或方法;不在类的实例上。所以你必须使用类名来引用它们;不是实例名称。您没有在代码中指定类名。
<mx:Image source="{getStyle(ClassName.SOMESTYLE)}" />
下面是一些代码,显示了在定义它的同一个类中访问静态常量。此文件名为 StaticVariablesInSameClass_SO:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Style>
@namespace s "library://ns.adobe.com/flex/spark";
@namespace mx "library://ns.adobe.com/flex/mx";
s|Application{
someStyle : 'https://www.flextras.com/Assets/images/flextras_logo3.gif';
}
</fx:Style>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private static const SOMESTYLE:String = "someStyle";
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
trace(this.getStyle('someStyle'));
trace(this.getStyle(StaticVariablesInSameClass_SO.SOMESTYLE));
}
]]>
</fx:Script>
</s:Application>