Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks as though your <code>Volume</code> class is as you said, mostly complete and self-contained. This is good, as it will make instantiating a new instance of it within your document class easier. </p> <p>Within the document, class, to instantiate a new class, you can do the following:</p> <pre><code>var new_volume:Volume = new Volume(); addChild(new_volume); </code></pre> <p>It's important to note that the <code>stage</code> does not come into scope within your <code>Volume</code> class <strong>until you have added it to the stage from within it's parent class</strong> (in this case, it's parent class is the document class).</p> <p>So these two lines:</p> <pre><code>public var xPos:Number=stage.stageWidth/2; public var yPos:Number=stage.stageHeight/2; </code></pre> <p>don't work, as the stage is undefined there. To wait until you get know <code>stage</code> is defined, you can use an <code>Event.ADDED_TO_STAGE</code> event listener. So you can re-write your <code>Volume</code> class a bit to look more like this:</p> <pre><code>package { /* Imports here */ public class Volume extends Sprite { /* Other vars here */ public var xPos:Number; public var yPos:Number; public function Volume(){ /* Other assignments that are not stage-dependant can go here */ this.addEventListener(Event.ADDED_TO_STAGE, onStage); } private function onStage(e:Event):void{ //We remove it immediately so that it doesn't get called multiple times //As the instance is added to the display list tree this.removeEventListener(Event.ADDED_TO_STAGE, onStage); xPos = stage.stageWidth/2; yPos = stage.stageHeight/2; /* Now that we have a reference to the stage, let's go ahead and create our slider */ init(); } </code></pre> <p>from there you can go on with business as usual, and just alter your variable values as needed to get the class to work within the confines of your player environment/document class.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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