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 6533621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:09:01+00:00 2026-05-25T10:09:01+00:00

I am developing a Jigsaw puzzle in Flash. I am developing a class for

  • 0

I am developing a Jigsaw puzzle in Flash. I am developing a class for puzzle piece. The code of the PuzzlePiece class in given as follows.

package 
{
import flash.display.MovieClip;
import flash.events.MouseEvent;

public class PuzzlePiece extends MovieClip
{

    private var pieceX:Number;
    private var pieceY:Number;

    private var pieceXRandom:Number;
    private var pieceYRandom:Number;


    public function PuzzlePiece(pieceXRandom:Number,pieceYRandom:Number)
    {
        this.pieceXRandom = pieceXRandom;
        this.pieceYRandom = pieceYRandom;
        this.addEventListener(MouseEvent.MOUSE_DOWN,Drag);

        positionClips();
        this.gotoAndStop(2);

        this.holder_mc.width = this.holder_mc.height = 60;
        this.mask1_mc.width = this.mask2_mc.width = 60;
        this.mask1_mc.height = this.mask2_mc.height = 60;

    }

    private function positionClips():void
    {
        this.x = pieceXRandom;
        this.y = pieceYRandom;
    }

    private function Drag(e:MouseEvent)
    {
        switch (e.type)
        {
            case 'mouseDown' :
                this.startDrag();
                this.addEventListener(MouseEvent.MOUSE_UP,Drag);
                break;

            case 'mouseUp' :
                this.stopDrag();
                this.removeEventListener(MouseEvent.MOUSE_UP,Drag);
                /*var m:*=this.parent;
                m.pos(this.x,this.y);*/

        }

    }
}
}

This is code in the main timeline.

//Global variables//
var imageDimension:Number = 360;
var gridType:Number = 6;
var puzzlePieceShape:String = "Sqaure";
var imageLoader:Loader = new Loader();
var bitmapArray:Array = [];
var puzzlePiece:PuzzlePiece;

var bitmapManip:BitmapManipulation;

loadImage();

function loadImage()
{
    imageLoader.load(new URLRequest("Mohanlal.jpg"));//The image being loaded is of 360*360
    imageHolder_mc.addChild(imageLoader);//imageHolder_mc is an empty MovieClip on stage
    imageHolder_mc.visible = false;
    imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, layoutPieces);
}

function layoutPieces(evt:Event)
{
    bitmapManip = new BitmapManipulation(imageDimension,gridType);
    bitmapArray = bitmapManip.getBitmapImagePieces(imageHolder_mc);

    for (var j:uint =0; j<bitmapArray.length; j++)
    {

        for (var k:uint=0; k<bitmapArray[j].length; k++)
        {

            var bitmap:Bitmap = new Bitmap(bitmapArray[j][k]);
            puzzlePiece = new PuzzlePiece(400 * Math.random(),400 * Math.random());
            addChild(puzzlePiece);
            puzzlePiece.holder_mc.addChild(bitmap);

        }
    }
}

Bitmap Manipulation class

package 
{
    import flash.display.MovieClip;
    import flash.display.BitmapData;
    import flash.geom.Point;
    import flash.geom.Rectangle;

    public class BitmapManipulation extends MovieClip
        {
            private var imageDimension:Number;
            private var gridDimension:Number;

            public function BitmapManipulation(imageDimension:Number,gridDimension:Number)
            {
                this.imageDimension = imageDimension;
                this.gridDimension = gridDimension;

            }

            public function getBitmapImagePieces(imageMC:MovieClip):Array
            {
                var bitmapArray:Array = [];
                var imageBitmapData:BitmapData = new BitmapData(imageMC.width,imageMC.height);
                imageBitmapData.draw(imageMC);
                var tileDimesion:Number = this.imageDimension / this.gridDimension;

                for (var i:uint = 0; i<this.gridDimension; i++)
                {
                    bitmapArray[i] = new Array();

                    for (var j:uint = 0; j<this.gridDimension; j++)
                    {

                        var tempData:BitmapData = new BitmapData(tileDimesion,tileDimesion);
                        var tempRect:Rectangle = new Rectangle(((tileDimesion) * i),((tileDimesion) * j),tileDimesion,tileDimesion);
                        tempData.copyPixels(imageBitmapData,tempRect,new Point(0,0));
                        bitmapArray[i][j] = tempData;

                    }
                }

                return(bitmapArray);

            }
        }
    }

The puzzlepiece movieclip has two layers

Mask Layer - Two masks. One rectangular and one triangular in frame 1 and 2.
Holder Layer - holder_mc

I am trying to set the dimension of movieclips inside the puzzle piece using the code in PuzzlePiece class.

But I am getting this error.

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at PuzzlePiece()[C:\Users\Shabeeb\Desktop\Puzzle OOP\PuzzlePiece.as:26]
    at PuzzlePiece_fla::MainTimeline/layoutPieces()[PuzzlePiece_fla.MainTimeline::frame1:33]

Line number 33 in main timeline class calls 

this.holder_mc.width = this.holder_mc.height = 60;
this.mask1_mc.width = this.mask2_mc.width = 60;
this.mask1_mc.height = this.mask2_mc.height = 60;

Is it wrong to access it like that. The PuzzlePiece is the export for a puzzle clip.

For the time being I am hard coding the dimension as 60. I have aloso uploaded the fla and as files.

https://rapidshare.com/files/4248268633/Puzzle_OOP.zip

  • 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-05-25T10:09:02+00:00Added an answer on May 25, 2026 at 10:09 am

    This may shed some insight for you on what is going on http://www.developria.com/2010/04/combining-the-timeline-with-oo.html . (In a nutshell, you can’t access objects that are declared on the timeline until the Flash player has actually created them.)

    Note that I would not suggest that you use frame scripts that do anything more complicated than stop(), especially if you’re also going to use document classes.

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

Sidebar

Related Questions

Developing websites are time-consuming. To improve productivity, I would code a prototype to show
Developing server side code i finally got my eyes X-crossed trying to write -
Developing ios app. I have an object class Product.h and .m respectively along with
When developing for Android in Eclipse, for example, it's easy to automatically import packages
Developing a .NET WinForms application: how can I check if the window is in
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.
Developing a website and just trying to get back into the swing of (clever)
Developing a project of mine I realize I have a need for some level
Developing a C# .NET 2.0 WinForm Application. Need the application to close and restart
When developing a desktop application in .NET, is it possible to not require 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.