Skip to main content
Participant
July 13, 2013
Answered

Line 45 1120: Access of undefined property releaseFood

  • July 13, 2013
  • 2 replies
  • 759 views

package

     {

          import flash.display.MovieClip;

          import flash.events.*;

          import flash.display.Stage;

          public class Main extends MovieClip

          {

               public static  var shooter:Artillery;

               public static var circle: Circle;

               public static var hungered: Hungered;

               public static var food: Food;

               public static var level:int = 0;

               public static var stage:Stage

               public function Main()

               {

                    StartGame(level);

               }

               public function StartGame(level:int):void

               {

                    circle = new Circle(level);

                    addChild(circle);

                    hungered = new Hungered();

                    addChild(hungered);

                    shooter  =new Artillery();

                    addChild(shooter);

                    stage.addEventListener(MouseEvent.CLICK,releaseFood)

               }

               public  function releaseFood(e:MouseEvent):void

               {

                    food = new Food();

                    addChild(food)

               }

               public static function StopGame():void

               {

                    circle.parent.removeChild(circle);

                         hungered.parent.removeChild(hungered);

                    shooter.parent.removeChild(shooter);

                    food.parent.removeChild(food);

                          stage.addEventListener(MouseEvent.CLICK,releaseFood)

                    trace("stop")

               }

          }

     }

This topic has been closed for replies.
Correct answer kglad

use:

package

     {

          import flash.display.MovieClip;

          import flash.events.*;

          import flash.display.Stage;

          public class Main extends MovieClip

          {

               public static  var shooter:Artillery;

               public static var circle: Circle;

               public static var hungered: Hungered;

               public static var food: Food;

               public static var level:int = 0;

               public static var stage:Stage

               public function Main()

               {

                    StartGame(level);

               }

               public function StartGame(level:int):void

               {

                    circle = new Circle(level);

                    addChild(circle);

                    hungered = new Hungered();

                    addChild(hungered);

                    shooter  =new Artillery();

                    addChild(shooter);

                    stage.addEventListener(MouseEvent.CLICK,releaseFood)

               }

// this could and/or should be private

               public  function releaseFood(e:MouseEvent):void

               {

                    food = new Food();

                    addChild(food)

               }

// this could and/or should be private

               public function StopGame():void

               {

                    circle.parent.removeChild(circle);

                         hungered.parent.removeChild(hungered);

                    shooter.parent.removeChild(shooter);

                    food.parent.removeChild(food);

                          stage.addEventListener(MouseEvent.CLICK,releaseFood)

                    trace("stop")

               }

          }

     }

2 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
July 13, 2013

use:

package

     {

          import flash.display.MovieClip;

          import flash.events.*;

          import flash.display.Stage;

          public class Main extends MovieClip

          {

               public static  var shooter:Artillery;

               public static var circle: Circle;

               public static var hungered: Hungered;

               public static var food: Food;

               public static var level:int = 0;

               public static var stage:Stage

               public function Main()

               {

                    StartGame(level);

               }

               public function StartGame(level:int):void

               {

                    circle = new Circle(level);

                    addChild(circle);

                    hungered = new Hungered();

                    addChild(hungered);

                    shooter  =new Artillery();

                    addChild(shooter);

                    stage.addEventListener(MouseEvent.CLICK,releaseFood)

               }

// this could and/or should be private

               public  function releaseFood(e:MouseEvent):void

               {

                    food = new Food();

                    addChild(food)

               }

// this could and/or should be private

               public function StopGame():void

               {

                    circle.parent.removeChild(circle);

                         hungered.parent.removeChild(hungered);

                    shooter.parent.removeChild(shooter);

                    food.parent.removeChild(food);

                          stage.addEventListener(MouseEvent.CLICK,releaseFood)

                    trace("stop")

               }

          }

     }

Participant
July 14, 2013

thank you
but I want to call StopGame() from another class
if it is private I cant do that

kglad
Community Expert
Community Expert
July 14, 2013

then leave it public or use internal

kglad
Community Expert
Community Expert
July 13, 2013

nothing in your static function can reference the instance method releaseFood().

to remedy, either use instance methods and properties or use static methods and properties.  trying to mix both in the same class is likely to cause problems.

Participant
July 13, 2013

sorry I am new at oop
so can you write the correct code plz ?