How to associate a function with a component programmatically in ActionScript?

I am trying to provide my own labelFunction for the CategoryAxis program programmatically, but I am completely at a dead end. The usual way is to do it in your MXML file, but I want to do it in the Actionscript file.

The usual way to do this is:

<mx:Script>
    <![CDATA[
       private function categoryAxis_labelFunc(item:Object, 
                prevValue:Object, 
                axis:CategoryAxis, 
                categoryItem:Object):String {
                return "Some String";
            }
      ]]>
</mx:Script>

<mx:CategoryAxis labelFunction="categoryAxis_labelFunc" />

But I want to achieve the same thing in my CategoryAxis subclass, something like:

public class FauxDateAxis extends CategoryAxis {

    public function FauxDateAxis() {
        super();
        labelFunction = categoryAxis_labelFunc // Doesn't work of course.
    }

        private function categoryAxis_labelFunc(item:Object, 
                prevValue:Object, 
                axis:CategoryAxis, 
                categoryItem:Object):String {
            return "Another String";
    }   

}
+3
source share
3 answers

Well, I am puzzled by your problem because it works absolutely normal for me.

CategoryAxis Adobe Flex:   http://livedocs.adobe.com/flex/3/langref/index.html?mx/charts/CategoryAxis.html&mx/charts/class-list.html, (, ), , .

<mx:CategoryAxis id="haxis" categoryField="Date" title="Date"/>

<local:FauxDateAxis id="haxis" categoryField="Date" title="Date"/>

" " .

Flex 3, .

,

+2

, .

labelFunction CategoryAxis , , . :

function(item:Object, field:String, index:int, pct:Number)

Flex, , , , , ,

public function FauxDateAxis() {
    super();
    labelFunction = function(item:Object, field:String, index:int, pct:Number) {
       return "string";
    }
}

Flex 3 Pro.

, http://blog.flexexamples.com/2007/11/16/creating-a-custom-label-function-on-a-flex-linechart-controls-category-axis/ ( , , ). , .

; API , Flex 2 Flex 3, , , .

+1

, , , , , , , .

0

Source: https://habr.com/ru/post/1699252/


All Articles