you can't reference the stage in the Mountain class until it is added to the
Display List. try this

package {
       import flash.display.Sprite;
import flash.events.Event;

       public class Mountain extends Sprite {
               private var x0:Number;
               private var y0:Number;
               private var x1:Number;
               private var y1:Number;
               private var x2:Number;
               private var y2:Number;

               public function Mountain() {
               this.addEventListener(Event.ADDED_TO_STAGE, onStageAdded);


               }
               public function init():void {
                       graphics.beginFill(0x256251);
                       graphics.moveTo(x0,y0);
                       graphics.curveTo(x1,y1,x2,y2);
                       graphics.lineTo(x2, stage.stageHeight);
                       graphics.lineTo(0, stage.stageHeight);
                       graphics.endFill();
               }
               public function onStageAdded(e:Event):void
               {
                   x0:Number =0;
                  y0 =stage.stageHeight -150;
                   x1=stage.stageWidth/2;
                  y1:Number=100;
                   x2 =stage.stageWidth;
                   y2:Number =stage.stageHeight -150;
                   init();

              }
 }

On Mon, Mar 17, 2008 at 11:28 AM, Pedro Kostelec <[EMAIL PROTECTED]>
wrote:

> I added the () to it but still doesn't work:
>
> package {
>        import flash.display.Sprite;
>        import flash.events.Event;
>        import flash.filters.*;
>
>        public class RisingCroix extends Sprite {
>                private var croix:Croix;
>                private var croix2L:Croix2;
>                private var croix2R:Croix2;
>                 private var sun:Sun;
>                private var mountain:Mountain;
>
>                private var vy:Number=5;
>                private var glowFilter:GlowFilter;
>                 private var glowSun:GlowFilter;
>                 private var blurFilter:BlurFilter;
>                private var blurFilter2:BlurFilter;
>
>                public function RisingCroix() {
>                        init();
>                }
>                private function init():void {
>                         sun = new Sun();
>                        addChild(sun);
>                        sun.x = stage.stageWidth / 2;
>                        sun.y=stage.stageHeight;
>
>                        croix=new Croix();
>                        addChild(croix);
>                        croix.x=stage.stageWidth / 2;
>                        croix.y=stage.stageHeight;
>
>                        croix2L = new Croix2();
>                        addChild(croix2L);
>                        croix2L.x=stage.stageWidth /4;
>                        croix2L.y = stage.stageHeight;
>
>                        croix2R = new Croix2();
>                        addChild(croix2R);
>                        croix2R.x = stage.stageWidth /4 *3;
>                        croix2R.y = stage.stageHeight;
>
>                         mountain= new Mountain();
>                         addChild(mountain);
>                        mountain.x = stage.stageWidth/2;
>                        mountain.y = stage.stageHeight/2;
>
>                         glowFilter = new GlowFilter(0xFFFFCC, 0.6, 30, 30,
> 3, 1);
>                        blurFilter = new BlurFilter(3,3,1);
>                         blurFilter2 = new BlurFilter(13,13,3);
>                         glowSun = new GlowFilter(0xFF6600, 1, 50, 50, 2,
> 1, true);
>
>                        croix.filters = [blurFilter, glowFilter];
>                        croix2R.filters = croix2L.filters =[blurFilter2];
>                         sun.filters = [glowSun, blurFilter2];
>
>                        addEventListener(Event.ENTER_FRAME, onEnterFrame);
>                }
>                public function onEnterFrame(event:Event):void {
>                         //...
>                        }
>
>                }
>        }
> }
>
> Mountain class final:
>
> package {
>        import flash.display.Sprite;
>
>        public class Mountain extends Sprite {
>                 private var x0:Number =0;
>                private var y0:Number =stage.stageHeight -150;
>                private var x1:Number=stage.stageWidth/2;
>                private var y1:Number=100;
>                private var x2:Number =stage.stageWidth;
>                private var y2:Number =stage.stageHeight -150;
>
>                public function Mountain() {
>                        init();
>                }
>                public function init():void {
>                        graphics.beginFill(0x256251);
>                        graphics.moveTo(x0,y0);
>                        graphics.curveTo(x1,y1,x2,y2);
>                        graphics.lineTo(x2, stage.stageHeight);
>                        graphics.lineTo(0, stage.stageHeight);
>                        graphics.endFill();
>                 }
>        }
> }
>
> On Mon, Mar 17, 2008 at 3:58 PM, jonathan howe <[EMAIL PROTECTED]>
> wrote:
> > Missing () after Mountain instantiation, first of all...
> >
> >  var mountain:Mountain = new Mountain();
> >
> >
> >
> >
> >
> >  On Mon, Mar 17, 2008 at 3:36 PM, Pedro Kostelec <[EMAIL PROTECTED]>
> wrote:
> >
> >  > Hi
> >  >  (posted in flashnewbies but the list is not very active and i need
> to
> >  > solve this problemas soon as possible)
> >  >  i have a problem while creating a as3 short animation:
> >  >
> >  >  When i test the movie(all done with as3) i get this:
> >  >
> >  >  TypeError: Error #1009: Cannot access a property or method of a null
> >  >  object reference.
> >  >    at Mountain/init2()
> >  >    at Mountain$iinit()
> >  >    at RisingCroix/::init()
> >  >    at RisingCroix$iinit()
> >  >
> >  >
> >  >  my code:
> >  >  package {
> >  >        import flash.display.Sprite;
> >  >        import flash.events.Event;
> >  >        import flash.filters.*;
> >  >
> >  >        public class RisingCroix extends Sprite {
> >  >                private var croix:Croix;
> >  >                private var croix2L:Croix2;
> >  >                private var croix2R:Croix2;
> >  >
> >  >                private var vy:Number=5;
> >  >                private var glowFilter:GlowFilter;
> >  >                private var blurFilter:BlurFilter;
> >  >                private var blurFilter2:BlurFilter;
> >  >
> >  >                public function RisingCroix() {
> >  >                        init();
> >  >                }
> >  >                private function init():void {
> >  >                        croix=new Croix;
> >  >                        addChild(croix);
> >  >                        croix.x=stage.stageWidth / 2;
> >  >                        croix.y=stage.stageHeight;
> >  >
> >  >                        croix2L = new Croix2;
> >  >                        addChild(croix2L);
> >  >                        croix2L.x=stage.stageWidth /4;
> >  >                        croix2L.y = stage.stageHeight;
> >  >
> >  >                        croix2R = new Croix2;
> >  >                        addChild(croix2R);
> >  >                        croix2R.x = stage.stageWidth /4 *3;
> >  >                        croix2R.y = stage.stageHeight;
> >  >
> >  >                        var mountain:Mountain = new Mountain //i guess
> >  > it is here wher it stucks
> >  >                        addChild(mountain);
> >  >                        mountain.x = stage.stageWidth / 2;
> >  >                        mountain.y = stage.stageHeight / 2;
> >  >
> >  >                        glowFilter = new GlowFilter(0xFFFF00, 0.6, 30,
> >  > 30, 2, 1);
> >  >                        blurFilter = new BlurFilter(6,6,1);
> >  >                        blurFilter2 = new BlurFilter(13,13,3);
> >  >
> >  >                        addEventListener(Event.ENTER_FRAME,
> onEnterFrame);
> >  >                }
> >  >                public function onEnterFrame(event:Event):void {
> >  >                        if (croix.y>stage.stageHeight/2) {
> >  >                                croix.y -=vy;
> >  >                        }
> >  >                        if (croix2R.y>stage.stageHeight/2-10) {
> >  >                                croix2R.y -= vy/3*2;
> >  >                                croix2L.y  -= vy/3*2;
> >  >                        }
> >  >                        croix.filters = [blurFilter, glowFilter];
> >  >                        croix2R.filters = croix2L.filters=[blurFilter2];
> >  >
> >  >                }
> >  >        }
> >  >  }
> >  >
> >  >  and the Mountain CLass
> >  >
> >  >  package {
> >  >        import flash.display.Sprite;
> >  >
> >  >        public class Mountain extends Sprite {
> >  >                private var color1:uint=0x003300;
> >  >                private var color2:uint=0x001700;
> >  >
> >  >                public function Mountain() {
> >  >                        init2();
> >  >                }
> >  >                public function init2():void {
> >  >
> >  >                        graphics.beginFill(color1);
> >  >                        graphics.drawRect(0,0,stage.stageWidth,
> >  > stage.stageHeight/2);
> >  >                        graphics.endFill();
> >  >                }
> >  >        }
> >  >  }
> >  >
> >  >
> >  >
> >  >  --
> >  >  Pedro D.K.
> >  > _______________________________________________
> >  > Flashcoders mailing list
> >  > Flashcoders@chattyfig.figleaf.com
> >  > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >  >
> >
> >
> >
> >  --
> >  -jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101
> >  _______________________________________________
> >  Flashcoders mailing list
> >  Flashcoders@chattyfig.figleaf.com
> >  http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
> >
>
>
>
> --
> Pedro D.K.
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to