Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I bind a function to a component programatically in Actionscript?

I am trying to provide my own labelFunction for a CategoryAxis programatically but am completely stumped. The regular way is to do it in your MXML file, but I want to do it in my Actionscript file.

The regular way of doing it 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 subclass of CategoryAxis, 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";
    }   

}
like image 876
Hates_ Avatar asked Jul 12 '26 13:07

Hates_


1 Answers

Well, I'm baffled by your problem, because it works absolutely fine for me.

I took the example application for CategoryAxis from the Adobe Flex site: http://livedocs.adobe.com/flex/3/langref/index.html?mx/charts/CategoryAxis.html&mx/charts/class-list.html, added your code verbatim (well except for adding package and import statments), and it worked just like you want it to.

In the example, I modified the line

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

to read

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

and it displayed "Another String" at the base of each column.

I'm using Flex 3, if that matters.

Good Luck, Randy Stegbauer

like image 178
Randy Stegbauer Avatar answered Jul 14 '26 04:07

Randy Stegbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!