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

  • Home
  • SEARCH
  • 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 9246767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:34:11+00:00 2026-06-18T09:34:11+00:00

This looks long but it’s a really simple question. With the following code: public

  • 0

This looks long but it’s a really simple question. With the following code:

public class Map extends MovieClip
{

    var dragdrops:Array;
    var numOfMatches:uint = 0;
    var speed:Number = 25;

    public function Map()
    {
        // constructor code
        var dragdrops = [one_mc,two_mc,three_mc,four_mc,five_mc,six_mc];

        var currentObject:DragDrop;

        for (var i:uint = 0; i < dragdrops.length; i++)
        {
            currentObject = dragdrops[i];
            currentObject.target = getChildByName(currentObject.name + "_target");
        }


    }

    public function match():void
    {
        numOfMatches++;
        if(numOfMatches == dragdrops.length)
        {
            win.addEventListener(Event.ENTER_FRAME, winGame);
        }
    }

I get this error

TypeError: Error #1009: Cannot access a property or method of a null
object reference. at Map/match()[G:_flash\edu\drag_drop\Map.as:34]
at DragDrop/drop()[G:_flash\edu\drag_drop\DragDrop.as:41]

I assume it’s because i’m referencing the global array “dragdrops” which currently is a null value.

However the code below works perfectly, by passing the dragdrops.length value to another global variable.

public class Map extends MovieClip
{

    var dragdrops:Array;
    var dragdropslength:Number = 0;
    var numOfMatches:uint = 0;
    var speed:Number = 25;

    public function Map()
    {
        // constructor code
        var dragdrops = [one_mc,two_mc,three_mc,four_mc,five_mc,six_mc];

        var currentObject:DragDrop;

        for (var i:uint = 0; i < dragdrops.length; i++)
        {
            currentObject = dragdrops[i];
            currentObject.target = getChildByName(currentObject.name + "_target");
        }

        dragdropslength = dragdrops.length

    }

    public function match():void
    {
        numOfMatches++;
        if(numOfMatches == dragdropslength)
        {
            win.addEventListener(Event.ENTER_FRAME, winGame);
        }
    }

While this works fine I was wondering if there was a more elegant solution to be able to reference the dragdrops value from within the Map() constructor without the extra variable.

  • 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-18T09:34:12+00:00Added an answer on June 18, 2026 at 9:34 am

    You can assign to “dragdrops” directly in the constructor, thereby initializing the instance variable. Just remove the preceding “var” in the first line of the Map constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(This looks like a long question, but it's not really, honest!) I am trying
Note : the code looks long but its simple psuedo code for demo purpose.
This looks like a long shot, but does anyone know of a way to:
This looks simple but I am confused: The way I create a vector of
This looks like something simple but I could not find the answer so far
So, this may be a really stupid question, but I'm obviously missing something here.
This Might be a long question but please do bear with me a little.
The example looks a bit long. But it is necessary to understand my question.
I have the following script (it looks long, but well commented). Problem is, i
I know this looks a bit long but i tried to explain the problem

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.