# Senocular's Transform Tool:Cannot access a property or method of a null object refere

**URL:** <https://forum.kirupa.com/t/senoculars-transform-tool-cannot-access-a-property-or-method-of-a-null-object-refere/317635>\
**Category:** flash\
**Created:** [December 28, 2010, 11:07am UTC](https://forum.kirupa.com/t/senoculars-transform-tool-cannot-access-a-property-or-method-of-a-null-object-refere/317635 "2010-12-28T11:07:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![spectator](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@spectator](https://forum.kirupa.com/u/spectator)\
**Post date:** [December 28, 2010, 11:07am UTC](https://forum.kirupa.com/t/senoculars-transform-tool-cannot-access-a-property-or-method-of-a-null-object-refere/317635/1 "2010-12-28T11:07:08Z")

</div>

Hello :). I am using **Senocular’s Transform Tool:** (great tool (bow)). What am I doing Is this:

1. I draw objects with the mouse

```php
doorCreation = new MovieClip();
doorCreation.graphics.lineStyle(2, 0x000000);
doorCreation.graphics.beginFill(0x222222, .3);
doorCreation.graphics.drawRect(_corner.x, _corner.y, mouseX - _corner.x, mouseY - _corner.y);
doorCreation.name = String(doorsCounter);
addChild(doorCreation);
                
doorsList.push(doorCreation);
doorLoadedImage.push(0);
CANVAS.graphics.clear();
removeChild(CANVAS);
_corner = null;
selectedDoor = doorsList[doorsList.length - 1];
doorsCounter++;

```

\_corner is Point with the starting x and y positions. On MouseUp the code above is called. doorCreation is private variable and I add it to the doorsList array. CANVAS is used to draw the live preview ot the door.

1. I have an image scroller and from it the user selects img and I load it to the drawing:

```php
var doorName:String = selectedDoor.name;
var xVal:Number= doorXValues[selectedDoor.name];
var yVal:Number = doorYValues[selectedDoor.name];
doorLoadedImage[selectedDoor.name] = 1;
var ar:MovieClip = new MovieClip();
_imageLoader.loadImage(doorData[1], ar, selectedDoor.width, selectedDoor.height);
 addChild(ar);
selectedDoor.graphics.clear();
removeChild(selectedDoor);
selectedDoor = ar;
selectedDoor.x = xVal;
selectedDoor.y = yVal;
selectedDoor.name = doorName;
defaultTool.target = selectedDoor;

```

here I set a target to the Transform tool and everything is working fine. If I draw another door and choose picture it is also working fine.

1. There is one MovieClip called LayersContainer. For every door I create simple MovieClip containing the name of the door. So when the user clicks on certain layer I want the drawing to be transformable.

```php
//set active layer
        public function setActiveDoorLayer(id:Number):void {
            removeAllDoorLayerListeners();
            selectedDoor = doorsList[id];
            selectedDoor.alpha = 1;
            defaultTool.target = null;
            fixTarget();
        }
        
        private function fixTarget():void {
            if (doorLoadedImage[selectedDoor.name] == "1") {
                if (selectedDoor != null) {
                    trace(selectedDoor);
                    //THE PROBLEM IS HERE 
                    defaultTool.target = selectedDoor;
                } else {
                    trace("nothing");
                }
            }
        }
        
        //reset all options
        private function resetAllDoors():void {
            defaultTool.target = null;
            for (var i:int=0; i < doorsList.length; i++) {
                var element:* = doorsList*;
                if (i == doorsList.length - 1) {
                    element.alpha = 1;
                } else {
                    element.alpha = 0.3;
                }
                
            }
        }

```

I want the door to be transformable only if there is picture in it. That’s why I am using this array doorLoadedImage. If doorLoadedImage value for the current door is 1, so there is already img loaded and I should set the target of the Transform tool. The problem is that If I set the defaultTool.target = selectedDoor; it gives me this error:

> TypeError: Error #1009: Cannot access a property or method of a null object reference.  
> at com.senocular.display::TransformTool/::raiseTarget()  
> at com.senocular.display::TransformTool/set target()  
> at src.ui::Scribble/::fixTarget()  
> at src.ui::Scribble/setActiveDoorLayer()  
> at Main/::layerDoorChoosedForEditing()  
> at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()  
> at flash.events::EventDispatcher/dispatchEvent()  
> at src.ui::layerMenuContainer/::changeSelectedDoor()  
> selectedDoor is declared as:

```php
private var selectedDoor:*;
private var doorCreation:MovieClip;

```

What I understand from the error is that: selectedDoor is not global variable. But it should be global first it is on the stage, I get it from the array. I don’t know how to fix the problem 🙂

Any help is appreciated. Thank you in advance.
