1
votes

Hi I'm currently learning how to use Flash so I'm creating a colouring book as a project I'm just having trouble with my code though. The Code I've written is:

import coloring; 
PrevBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_14);

function fl_ClickToGoToAndStopAtFrame_14(event:MouseEvent):void
 {
    gotoAndStop(40);
 }

    HomeBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_11);

    function fl_ClickToGoToAndStopAtFrame_11(event:MouseEvent):void
    {
    gotoAndStop(10);
    }


    NextBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_13);

    function fl_ClickToGoToAndStopAtFrame_13(event:MouseEvent):void
    {
    gotoAndStop(20);
    }



    HelpBtn.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_31);

    function fl_ClickToGoToAndStopAtFrame_31(event:MouseEvent):void
    {
    gotoAndStop(45);
    } 

Any help would be majorly appreciated. Thanks in advance!

**UPDATE: So I have created coloring.as and now import it in my code but I am now getting a further error when I get to my colouring sheet which reads:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at laurenBurke/frame15()
at flash.display::MovieClip/gotoAndStop()
at laurenBurke/fl_ClickToGoToAndStopAtFrame_4()**

The coloring.as file contains the following code

package {
import flash.display.Sprite;
import flash.geom.ColorTransform;
import flash.events.MouseEvent;

public class coloring extends Sprite {
    public var Design1:Design1 = new Design1();
    public var palette:palette_mc;
    public var pal_color:ColorTransform;
    public var colors:Array=new Array(0x000000,0xFFFFFF,0xFF0000,0xFF4040,0x333399,
                                      0x99CCCC,0xFFCC00,0xFFFF66,0x33CC00,0x99FF66,
                                      0x660099,0x9933FF,0xFF8000,0xFF9966,0xFF0099,
                                      0xFF99CC,0x0099CC,0x6699CC,0x666666,0xCCCCCC,
                                      0x003366,0x000033,0x99CC99,0x4E9A4E,0x9966FF,
                                      0x990066);
    public var current_color:int=0;
    public function coloring():void {
        addChild(Design1);
        Design1.addEventListener(MouseEvent.CLICK,on_Design1_click);
        for (var i:int=0; i<26; i++) {
            palette = new palette_mc();
            pal_color=palette.transform.colorTransform;
            pal_color.color=colors[i];
            palette.transform.colorTransform=pal_color;
            palette.x=40+i*60;
            palette.y=300;
            palette.ind=i;
            addChild(palette);
            palette.addEventListener(MouseEvent.CLICK,on_palette_click);
        }
    }
    public function on_palette_click(e:MouseEvent):void {
        var palette_clicked:palette_mc=e.currentTarget as palette_mc;
        current_color=palette_clicked.ind;
    }
    public function on_Design1_click(e:MouseEvent):void {
        for (var i:int = 0; i < Design1.numChildren; i++) {
            if (Design1.getChildAt(i).hitTestPoint(mouseX,mouseY,true)) {
                pal_color=Design1.getChildAt(i).transform.colorTransform;
                pal_color.color=colors[current_color];
                Design1.getChildAt(i).transform.colorTransform=pal_color;
            }
        }
    }
}
}
1
You should put your coloring class inside a coloring.as file and then import it to your Flash app or set it as your app's document class if it's the case. - akmozo
@akmozo Thank you for your reply! When I say I'm new to flash I mean Brand new. Would you mind explaining how I can do that? - Lauren Burke
OK, no problem. If that class is your document class, take a look here, and if it's just a class, you have to save it as coloring.as next to your Flash project then import it using : import coloring; ... - akmozo
Thanks a mill! I'll try that out now :) - Lauren Burke
@akmozo sorry for annoying you again but I tried what you suggested and think I done something wrong. Any advice? - Lauren Burke

1 Answers

0
votes

declaring Design1 with the same identifier as the class itself here:

public var Design1:Design1 = new Design1();

... is creating an ambiguous reference. Later on when you call addChild(Design1); you're potentially trying to add the class object itself, not an instance, to the stage. Try changing the var name to camel-case.