Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A class is made up of properties and functions: usually a constructor, which runs as soon as the class is instantiated (which in document classes is as soon as the application runs), and then other functions which are called in different ways.</p> <p>What you've done is that you've put all your functions <em>within</em> the constructor: not good. That's putting a function in a function, you just don't do that (although technically, you could make anonymous functions, but that's a different story).</p> <p>In addition, your event listeners should be added within the constructor. Adding event listeners is calling a function, and (to my knowledge) you can't call functions from a class outside of other functions.</p> <p>Basically, you should just take your functions out of the constructor, like this:</p> <pre><code>package{ import flash.display.MovieClip; import flash.events.MouseEvent; import flash.text.TextField; public class button extends MovieClip{ public function button() { home_btn.addEventListener(MouseEvent.CLICK, goHome); about_btn.addEventListener(MouseEvent.CLICK, goAbout); links_btn.addEventListener(MouseEvent.CLICK, goLinks); contact_btn.addEventListener(MouseEvent.CLICK, goContact); } function goHome (e:MouseEvent):void{ gotoAndStop("Home"); } function goAbout (e:MouseEvent):void{ gotoAndStop("About"); } function goLinks (e:MouseEvent):void{ gotoAndStop("Links"); } function goContact (e:MouseEvent):void{ gotoAndStop("Contact"); } } } </code></pre> <p>Another thing is that the file name should be identical to the class name. That is, your document class should be called <code>button.as</code> instead of <code>site1.as</code>. I'm not completely sure if it's 100% necessary in the Flash IDE (been a while since I've used it) since it didn't give an error, but even if it isn't it's good practice.</p> <p>It'd be a good idea to study up on how classes work, and document classes specifically. <a href="http://www.kirupa.com/developer/as3/classes_as3_pg1.htm" rel="nofollow">Here's a kirupa tutorial on classes</a>, and <a href="http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/" rel="nofollow">here's an ActiveTuts+ tutorial on document classes</a>.</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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