Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I call a button instance in an external .as script?
    primarykey
    data
    text
    <p>I've created a button in my stage. I've set the instance name to <code>init</code> and have the <code>MainTimeline</code> being called from an an external script:</p> <p>./Project/MyFlash.fla</p> <p>./Project/MyFlash_fla/MainTimeline.as</p> <p>I'm a beginner in Flash attempting to create a button and call it inside <code>MainTimeline.as</code>; the error returned: <code>ReferenceError: Error #1065: Variable init is not defined. at tfm::MainTimeline() </code></p> <p>I've also tried <code>var init:Button = new Button();</code> with no luck.</p> <p>More specifically, I am trying to do this:</p> <pre><code>function MainTimeline(){ //var init:Button = new Button(); init.addEventListener(MouseEvent.CLICK, begin); } function begin(){ addFrameScript(0, frame1); } </code></pre> <p>These are my imports (and I've added even useless ones in frustration):</p> <pre><code>import flash.display.*; import flash.events.*; import flash.net.*; import flash.system.*; import flash.utils.*; import flash.text.*; import flash.xml.*; import flash.media.*; import fl.controls.Button; import flash.*; import fl.*; import fl.controls.*; </code></pre> <p>Any possible solution?</p> <hr> <p>Update: I'm linking the external script under the stage property, <code>Class</code> as <code>MyFlash_fla.MainTimeline</code></p> <p>I've gotten the 'var not defined' error eliminated by simply adding <code>this.</code> preceding <code>init.add[...]</code>. My current error: <code>TypeError: Error #2007: Parameter listener must be non-null</code> <code>at flash.events::EventDispatcher/addEventListener()</code> <code>at tfm::MainTimeline()</code>. Sorry for not being completely clear at first, but I have a button in my stage, and I'm trying to have it execute the function, <code>begin()</code> whenever clicked. Currently, that error is returned and <code>begin()</code> is executed without any interaction.</p> <hr> <p>Update II. I've eliminated the last error by adding <code>event:Event</code> in <code>begin(event:Event){...</code>. Everything seems to be running smoothly. I'm left with an error though; it's not affecting anything, but I would still like to rid of it: <code>ReferenceError: Error #1065: Variable init is not defined.</code> <code>at tfm::MainTimeline/__setProp_init_Scene1_Layer1_0()</code> <code>at tfm::MainTimeline()</code> - What is this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload