Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7853597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:44:47+00:00 2026-06-02T19:44:47+00:00

Clouds, ducks, score display and waves should each have a class to govern their

  • 0

Clouds,
ducks,
score
display
and
waves
should
each
have
a
class
to
govern
their
movement
and
behavior.

When
ducks
are
clicked
on
they
are
“shot”
and
the
duck
is
removed
from
the
array
as
well
as
from
the
stage
(use
arrayName.splice()
for
this).
The
score
display
should
count
down
as
this
occurs.

The
number
of
ducks
left
should
be
a
property
within
the
Score
Display’s
class
and
adjusted
by
Main
when
the
ducks
are
shot.

When
all
the
ducks
are
“shot”
the
game
should
animate
the
“you
win”
message.
This
can
be
done
by
adding
and
removing
event
listeners
that
associate
an
ENTER
FRAME
event
with
an
animating
function.
(This
is
worth
only,
so
leave
it
for
last).

When
the
ducks
are
“shot”
the
waves
and
clouds
should
also
be
removed
from
view
AND
from
their
respective
arrays.

Game
should
reset
after
player
has
won
or
lost
many
times.
(not
just
once)

I have most of this done, I’m just having trouble with the scoreboard. Any tips on how to reset everything, and code the you win sign would help too.

import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;

[SWF(width="800", height="600", backgroundColor="#E6FCFF")]

public class Main extends Sprite
{
    private var _sittingDucks:Array = []; //always set your arrays with [] at the top
    public var _scoreDisplay:TextField


    public function Main()
    {
        //adding the background, and positioning it
        var background:Background = new Background();
        this.addChild(background);
        background.x = 30;
        background.y = 100;

        for(var i:uint = 0; i < 5; i++)
        {
            //adding the first cloud, and positioning it
            var clouds:Clouds = new Clouds();
            this.addChild(clouds);
            clouds.x = 130 + Math.random() * 600; //130 to 730
            clouds.y = 230;
            clouds.speedX = Math.random() * 3;
            clouds.width = clouds.height = 200 * Math.random()//randomly changes the clouds demensions
        }   

        var waves:Waves = new Waves();
        this.addChild(waves);
        waves.x = 0;
        waves.y = 510;
        waves.speedX = Math.random() * 3;


        for(var j:uint = 0; j < 8; j++)
        {
            var ducks:Ducks = new Ducks();
            this.addChild(ducks);
            ducks.x = 100 + j * 100;
            ducks.y = 475;
            _sittingDucks.push(ducks);
            ducks.addEventListener(MouseEvent.CLICK, ducksDestroy);
        }

        var waves2:Waves = new Waves();
        this.addChild(waves2);
        waves2.x = 0;
        waves2.y = 520;
        waves2.speedX = Math.random() * 3;

        var setting:ForeGround = new ForeGround();
        this.addChild(setting);
        setting.x = 0;
        setting.y = 50;
        setting.width = 920;

        var board:ScoreDisplay = new ScoreDisplay();
        this.addChild(board);
        board.x = 570;
        board.y = 35;

    }
    private function ducksDestroy(event:MouseEvent):void
    {
        //store the crow we clicked on in a new array
        var clickedDuck:Ducks = Ducks(event.currentTarget);

        //remove it from the crows array
        //find the address of the crow we are removing
        var index:uint = _sittingDucks.indexOf(clickedDuck);

        //remove it from the array with splice
        _sittingDucks.splice(index, 1);

        //remove it from my document's display list
        this.removeChild(clickedDuck);
    }
}


import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import ScoreDisplayBase; // always import the classes you are using

public class ScoreDisplay extends ScoreDisplayBase
{
    private var txt:TextField; // where is it initialized?
    private var score:uint = 0;

    public function ScoreDisplay()
    {
        super(); // do you init txt here?
    }

    public function scoreUpdate():void
    {
        score += 10; // ok, so I suppose that your score does not represent the remaining ducks as you said, just only a score
        txt.text = score.toString();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:44:48+00:00Added an answer on June 2, 2026 at 7:44 pm

    Aaaalrighty:

    1. You do want to create the TextField txt in ScoreDisplay’s constructor. Instantiate it, set its text to initial score (0), and addChild(txt).

    2. In order to set the score later, we’ll need a way to reference the display.

      //you want a reference to the ScoreDisplay, not this
      public var _scoreDisplay:TextField //no
      public var _scoreDisplay:ScoreDisplay //yes
      

      and when you create it in the Main constructor, we need to keep a reference.

      _scoreDisplay = :ScoreDisplay = new ScoreDisplay();
      this.addChild(_scoreDisplay );
      _scoreDisplay .x = 570;
      _scoreDisplay .y = 35;
      
    3. If you want to be able to reset the game, I would recommend taking the duck creation and placing it in a method outside the Main class’ constructor. You should also create a ‘reset’ function that sets the score (and the display) to 0 in ScoreDisplay.

      private function spawnDucks() {
          for(var j:uint = 0; j < 8; j++)
          {
              var ducks:Ducks = new Ducks();
              this.addChild(ducks);
              ducks.x = 100 + j * 100;
              ducks.y = 475;
              _sittingDucks.push(ducks);
              ducks.addEventListener(MouseEvent.CLICK, ducksDestroy);
          }
      }
      

      and then you call it in the constructor, and can call it again when you need to reset the game.

    4. ducksDestroy(event:MouseEvent) is going to be where you want to recalculate the score, check if you’ve won, show a message, and reset the game. You’ll need some kind of popup to display, here is a decent one if you don’t know where to get started at with that.

      private function ducksDestroy(event:MouseEvent):void
      {
          //store the crow we clicked on in a new array
          var clickedDuck:Ducks = Ducks(event.currentTarget);
      
          //remove it from the crows array
          //find the address of the crow we are removing
          var index:uint = _sittingDucks.indexOf(clickedDuck);
      
          //remove it from the array with splice
          _sittingDucks.splice(index, 1);
      
          //remove it from my document's display list
          this.removeChild(clickedDuck);
      
          //update the score
          _scoreDisplay.scoreUpdate();
      
          //Check if all the ducks are gone
          if (_sittingDucks.length == 0) {
              //All the ducks are dead, we've won the game!
      
              //create some kind of popup to display.
              //add it to the screen, have some form
              //of button (or a timer) take it away
      
              //whatever takes the popup away, have it call 'reset'
      
          }
      }
      
      private function reset():void
      {
          //write a reset method to clear the score
          _scoreDisplay.reset(); 
      
          //create some ducks and you're ready to go!
          spawnDucks();
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have 3 point clouds: first that has 3 points {x1,y1,z1}, {x2,y2,z2},
is there any Flex component displaying tag clouds ? (Each array item is composed
I have a 3D point clouds with million of points. I want to store
Silverlight filter/class for cloud generation? Some HLSL or just C# class for generating clouds?
I have point clouds that I need to visualize, currently I use Pixel based
Is there a Ruby/Rails library that I can generate word clouds (output should be
I have to create an automatic weather including rain, snow, clouds, fog and sunny.
I have an application that I'm currently building that requires me to display a
Is there a public, free web service that generates tag clouds? I'm looking for
I'm having a weird footer issue. http://jsfiddle.net/YGAvd/ The clouds at the bottom of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.