What are the limitations of public / private functions in actionscript functions?

I am currently maintaining some flex code and notice a lot of functions being declared as:

private function exampleFunc():void {
    ....
}

      

These functions are in the global scope and are not part of any particular class, so it is not clear to me which effect will be declared private. What are the limitations of the "private" qualifier for such functions?

+1


source to share


3 answers


The actionscript functions that are included in your mxmlc code will be available as part of your mxmlc component, which is compiled into a class behind the scenes. Therefore, marking them as private makes them inaccessible.

Here's an example, to make it clear, let's say you have the following component, we'll call it FooBox:


<!-- FooBox.mxml -->
<mx:Box xmlns:mx="http://www.macromedia.com/2003/mxml">
    <mx:Script><![CDATA[
        private function foo():void {
            lbl.text = "foo";
        }
        public function bar():void {
            lbl.text = "bar";
        }
    ]]></mx:Sctipt>
    <mx:Label id="lbl">
</mx:Box>


      

Now I can add FooBox to my application and use its functions:




<mx:Application
 xmlns:mx="http://www.macromedia.com/2003/mxml"
 xmlns:cc="controls.*"
>
     <mx:Script><![CDATA[
       private function init():void {
            fbox.foo(); // opps, this function is unaccessible.
            fbox.bar(); // this is ok...
       }
    ]]></mx:Sctipt>
    <cc:FooBox id="fbox" />
</mx:Application>

      

If the actionscript functions are included in the main application file, I think you can call the functions from the child control through the Application.application object, for example:


Application.application.bar(); 

      

if the bar function was placed in the main mxmlc code.

+2


source


What do you mean by the global sphere? Are these functions declared in the main MXML file?



In general, private means that functions can only be called from the class that declares them.

0


source


But when you put it in your ActionScript.as file does it still get complicated into a class?

Because asdoc doesn't like it.

0


source







All Articles