<p>I'm trying to call a function after I load some XML into Actionscript, and I'm just wondering how I call that function. Example:</p>

<pre><code>//Function Declarations
function parentFunction()
{
    function callMe()
    {
     textField.text = "lawl";
    }
}
</code></pre>

<p>Now, <strong>how do I call the "callMe()" function</strong> in a different part of the code, like an onRelease function?</p>

<pre><code>on(release)
{
callMe(); //doesn't work
parentFunction().callMe(); //doesn't work
parentFunction.callMe(); //doesn't work
}
</code></pre>

<p>ActionScript 2.0 is just so wonky! Any ideas?</p>

[{'answer_id': 40617, 'author': 'Michael Pryor', 'author_id': 245, 'author_profile': 'https://Stackoverflow.com/users/245', 'pm_score': 3, 'selected': True, 'text': '<p>Are you forced to declare callMe inside of parentFunction?  I assume so because otherwise you would just do</p>\n\n<p>function parent()  { }\nfunction callMe()  { }</p>\n\n<p>To be clear, a function can\'t own another function unless you provide some scope for that function to live in.</p>\n\n<p>So in JavaScript, you would do this by using the prototype object to declare the callMe function as a method of the object that parentFunction returned.</p>\n\n<p><a href="http://www.howtocreate.co.uk/tutorials/javascript/objects" rel="nofollow noreferrer">http://www.howtocreate.co.uk/tutorials/javascript/objects</a></p>\n\n<p>For ActionScript, read this article on Adobe\'s website:\n<a href="http://www.adobe.com/devnet/flex/articles/as_collections_03.html" rel="nofollow noreferrer">http://www.adobe.com/devnet/flex/articles/as_collections_03.html</a></p>\n\n<p>EDIT: After some more reading it appears the way you did things, you are actually declaring callMe as a <strong>private</strong> function.  See this article which should make the whole <a href="http://www.crockford.com/javascript/private.html" rel="nofollow noreferrer">private/public javascript issue</a> a lot more understandable.</p>\n'}, {'answer_id': 40729, 'author': 'MattSayar', 'author_id': 557, 'author_profile': 'https://Stackoverflow.com/users/557', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m an idiot. I forgot the whole "a function can\'t own another function" thing, so I figured out another way to do it. Thanks!</p>\n'}, {'answer_id': 113517, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Of course a function can "own" another function. this is ECMAScript remember. Just declare a variable inside your function and assign a function to it. You can then call your function by using the "call" method.</p>\n\n<p>function foo()\n{\n    trace("foo");</p>\n\n<pre><code>var bar = function()\n{\n    trace("bar");\n};\n\nbar.call();\n</code></pre>\n\n<p>}</p>\n\n<p>foo();</p>\n'}, {'answer_id': 286276, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<pre><code>//v--- on the frame\nfunction callMe(){\ntextArea.text='lawl';\n}\n//v---- for button\non(release){\ncallMe();\n}\n\n--- or -----\n</code></pre>\n\n<hr>\n\n<pre><code>//CUSTOM!!\n//v---- on frame\nfunction callMe(say){\ntextArea.text=say;\n}\n//v--- for button\non(release){\ncallMe('lawl');\n}\n</code></pre>\n"}, {'answer_id': 3237366, 'author': 'freak_ts', 'author_id': 390454, 'author_profile': 'https://Stackoverflow.com/users/390454', 'pm_score': 0, 'selected': False, 'text': '<p>Sorry for bad english, \nSet a handler for (Menu-)Buttons, whitch are located in a MC.</p>\n\n<p>MC "Buttons" on Stage (with 3 "testbtn" in it) @ first frame:</p>\n\n<pre><code>function SetMethod(Method:Function){\n    //trace(Method.call()); \n    //or something like:\n    testbtn1.addEventListener(MouseEvent.CLICK, Method);\n    testbtn2.addEventListener(MouseEvent.CLICK, Method);\n    testbtn3.addEventListener(MouseEvent.CLICK, Method);\n}\n</code></pre>\n\n<p>Stage (with MC "Butttons" in it) @ first frame:</p>\n\n<pre><code>function TheMenuListener(evt:Event):void{\n    trace(evt.target.name);\n\n}\n...\nButtons.SetMethod(this.TheMenuListener); \n</code></pre>\n\n<p>returns the testbtn.name</p>\n\n<p>Edit: Oh, it´s for AS3, but maybe helps!</p>\n'}]
['https://Stackoverflow.com/questions/40525', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/557/']