Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Package names are determined by the location from src. <code>src/my/package/name</code> is <code>my.package.name</code>. The package you import at the top of any class <strong>must</strong> match the actual package, otherwise the compiler will not find the class.</p> <p>So... say you have this structure in your folders:</p> <pre><code>src -&gt;my -&gt;package -&gt;name -&gt;ClassName </code></pre> <p>The class would be set up as so:</p> <pre><code>package my.package.name { public class ClassName { public function ClassName(){ //construct } } } </code></pre> <p>And you would import it using:</p> <pre><code>import my.package.name.ClassName; </code></pre> <p>or </p> <pre><code>import my.package.name.*; //only use the wildcard if every class in that package is being used, otherwise you will include code you may or may not need to in your project </code></pre> <p>Hopefully that helps explain packages and imports a bit.</p> <p>I also noticed that you are using the functions in your <code>CustomFuncs</code> class as if they were static (as you would with <code>Math.cos()</code> or similar). Your class is not set up to work this way. To do that, you need to use this <code>static</code> access modifier.</p> <pre><code>package sthreets { public class CustomFuncs { public static function TopDownMove(xy:String, rot:Number, offSet:Number):Number { if(xy=="x") { return cos(DegreesToRadions(rot)+offSet) } if(xy=="y") { return sin(DegreesToRadions(rot)+offSet) } } public static function DegreesToRadions(rot:Number):Number { return rot*Math.PI/180; } } } </code></pre> <p>The static access modifier means that the object (in this case, the functions) only exist once in any instance of the app, whereas a standard access modifier (<code>public</code>, <code>private</code>, <code>protected</code>, <code>internal</code>, <code>mx_internal</code>, <code>final</code>) create one object for every single instance of the <em>class</em>. Using the <code>static</code> access modifier allows you to access objects through <code>ClassName.objectName</code> because the objects belong to the class, not to the parent object. To get to those objects, you never have to instantiate (you will notice in the above code that I removed your constructor because it is unnecessary in this case).</p> <p><strong>Note:</strong> The following isn't necessarily directed at you, but I am including it for any future readers who might visit this question</p> <p>This <a href="http://greenethumb.com/article/27/public-private-protected-internal-access-modifiers-in-as3/" rel="nofollow">blog post</a> gives a fairly good rundown of the standard access modifiers. The comparisons it makes in relation to beer are incredibly good and incredibly easy for someone with limited knowledge about the modifiers to understand.</p> <p>I also suggest reading this <a href="http://en.wikipedia.org/wiki/Static_variable" rel="nofollow">Wikipedia article</a> on "Static Variable" to help you understand what a static object is and where and how to use it.</p> <p>AS3 strictly follows OOP (object oriented programming) and ECMAScript policies and its syntax is based heavily on Java. For these reasons, nearly every principle used by other OOP or ECMA languages applies to AS3 as well. This means that you can improve your AS3 skills by reading up on these principles, even if they are not specifically for AS3 (AS3 OOP tutorials are fairly limited in both quantity and quality so it can be difficult for someone who is learning AS3 as their first OOP language to learn these principles).</p>
    singulars
    1. This table or related slice is empty.
    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