0
votes

Two questions; Don't have code this time but they should be simple.

1) AS3 wants me to subclass a class that extends Stage; I'm not figuring out how to do this because it gives the error on the line of the package... code is basically:

package
{
    import flash.whatever.Stage
    public class thisclass extends Stage
    {
        public function thisclass()
        {
        }
    }
}

Not sure if I got all caps correct, I have the code at school. Do I need to put something in the function? If so what?

2) AS3 also wants me to use attributes for variables. var I:Boolean; if (I == true) The error is on the if line... Should I declare it as I.something? Change it to lower case? (would have tested but didn't think of it while I was at school)

UPDATE: I tried using .value and declaring and using the boolean as .something, nothing worked their, neither did trying to use lowercase... Couldn't get my blank stage class to work either... Another problem: what is the import flash.whatever.whatever for switch cases?

NEW STUFF:

package
{
    import flash.events.* 
    import flash.ui.*
    import flash.display.MovieClip

    public class tank extends MovieClip 
    {
        var ii:Boolean; var kk:Boolean; var ww:Boolean; var ss:Boolean;
        public function tank()
        {
            this.addEventListener(Event.ENTER_FRAME, update);
            stage.addEventListener(KeyboardEvent.KEY_UP, keyup);
            stage.addEventListener(KeyboardEvent.KEY_DOWN, keydown);
            this.x = 500; this.y = 500;
        }

        public function update(event:Event):void
        {
            var rotang = 0;
            var speed;
            if(ii==true)
            {
                rotang = rotang + 1;
            }
            if(kk==true)
            {
                rotang = rotang - 1;
            }
            if(ww==true)
            {
                rotang = rotang - 1; 
            }
            if(speed > 0)
            {
                speed = speed - 1;
            }
            if(speed < 0)
            {
                speed = speed + 1;
            }
            if(ss==true)
            {
                rotang = rotang + 1;
            }
            if(ii==true && ww==true)
            {
                speed = speed + 3;
            }
            if(kk==true && ss==true)
            {
                speed = speed - 3;
            }
            if(speed > 30)
            {
                speed = 30;
            }
            if(speed < -30)
            {
                speed = -30;
            }
            var vy =  Math.sin(this.degreesToRadians(rotang))*speed;
            var vx = Math.cos(this.degreesToRadians(rotang))*speed;
            this.y = this.y + vy;
            this.x = this.x + vx;
            this.rotation = rotang * Math.PI / 180;
        }
        public function degreesToRadians(param1:Number) : Number
        {
            return param1 * Math.PI / 180;
        }
        public function keyup(event:KeyboardEvent):void
        {
            switch(event.keyCode) 
            {
                case 87 :
                        ww = false;
                        break;
                case 83 :
                        ss = false;
                        break;
                case 73 :
                        ii = false;
                        break;
                case 75 :
                        kk = false;
                        break;
            }
        }

        public function keydown(event:KeyboardEvent):void
        {
            switch(event.keyCode) 
            {
                case 87 :
                        ww = true;
                        break;
                case 83 :
                        ss = true;
                        break;
                case 73 :
                        ii = true;
                        break;
                case 75 :
                        kk = true;
                        break;
            }
        }
    }
}
1
AS3 is a programming language, does it really want you to do these things? :) But seriously, you cannot create a class that extends the Stage class. If you can (meaning it doesn't generate a compile error), I'm not sure what you'd do with it. I'm not sure what the answer below means when they say it's working. But maybe I'm going to learn something new today. PS: We normally start our apps by extending the Sprite or MovieClip class, these things are added to the stage.Sunil D.
@SunilD. You can extend Stage, it's not declared as final, but it won't be of much use unless one would manage to replace Flash's native stage with his own subclass instance. And to user1743752, Sunil is right, you extend Sprite or MovieClip instead.Vesper
@Vesper, thanks! I learned something :) I just tried to extend the Stage class in Flash Builder and it compiled. But glad I was at least right about the "usefulness" of doing that.Sunil D.
Bump. What do I do instead of of stage class, if I just leave it blank with no package or anything will it cause a problem? I put the class to be connected to the stage in the .fla file...theHeretic
Oh, on the thing with extending stage that was an error, apparently the class for the stage is supposed to be in the form of extends movieclip...theHeretic

1 Answers

0
votes

try this :

package 
{
  import flash.display.MovieClip;

public class myClass extends MovieClip
{
    private var bln:Boolean = false;

    public function myClass()
    {
        if (bln == false)
        {
            trace("Value of boolean is false");
        }
     }
  } 
}

this is working.