0
votes

Coding in ActionScript I found an error I couldn't solve. I have a Flash file with a library, in which I have a MovieClip object called "SpriteGraphic" (it's linked and it's class name is also "SpriteGraphic")

Now I have an external class, in which I want to have an instance of that object:

    package {   

       import flash.display.Stage;
       import flash.geom.Point;
       import flash.display.MovieClip;

       public class Object 
       {        
           var spriteGraphic:SpriteGraphic;
           var velY:Number;
           var velX:Number;
           var IA:Number; 
           public function Object(posInit:Point, vel:Number , parAngle:Number, stageObj:Stage):void
           {
               spriteGraphic = new SpriteGraphic();             
               spriteGraphic.x = posInit.x;
               spriteGraphic.y = posInit.y;         
               trace(spriteGraphic.x);
               IA = parAngle;               
               velX = -vel * Math.cos(IA);
               velY = vel * Math.sin(IA);   
               stageObj.addChild(spriteGraphic);
          }
...

When I execute the output says spriteGraphic is null. How can I use the MovieClip from the library, and have a variable from that type in an external class?

Thanks a lot!

No one? Really? :c

1

1 Answers

0
votes

I'm assuming Object is a reserved word. Try using a different name for your class.

Also, your constructor shouldn't have a return type. Although the compiler will not warn you, it's technically an error to type it to void.

package {   

       import flash.display.Stage;
       import flash.geom.Point;
       import flash.display.MovieClip;

       public class MyObject 
       {        
           var spriteGraphic:SpriteGraphic;
           var velY:Number;
           var velX:Number;
           var IA:Number; 
           public function MyObject(posInit:Point, vel:Number , parAngle:Number, stageObj:Stage)
           {
               spriteGraphic = new SpriteGraphic();             
               spriteGraphic.x = posInit.x;
               spriteGraphic.y = posInit.y;         
               trace(spriteGraphic.x);
               IA = parAngle;               
               velX = -vel * Math.cos(IA);
               velY = vel * Math.sin(IA);   
               stageObj.addChild(spriteGraphic);
          }