# Type Coercion failed when accessing custom Class

**URL:** <https://forum.kirupa.com/t/type-coercion-failed-when-accessing-custom-class/293264>\
**Category:** flash\
**Created:** [July 26, 2009, 10:09am UTC](https://forum.kirupa.com/t/type-coercion-failed-when-accessing-custom-class/293264 "2009-07-26T10:09:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carsen](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Carsen](https://forum.kirupa.com/u/Carsen)\
**Post date:** [July 26, 2009, 10:09am UTC](https://forum.kirupa.com/t/type-coercion-failed-when-accessing-custom-class/293264/1 "2009-07-26T10:09:56Z")

</div>

Hello ppl.

I’m trying to make my own picture browser for my webpage, and have run into a problem I can’t solve. My guess is that this is kinda a newbie-problem, but anyway here I go… :thumb:

I have made a class (as an extention to MovieClip) in a seperate file where I can load a picture and later resize it into a thumbnail. I have no problem showing them, but when I tried to make a MouseEvent for clicking onto the shown thumbnail and then tries to access the instance the event sends me, I get :

_TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@22c30791 to ThumbNail.  
at PicBrowser\_fla::MainTimeline/clickedOnThumbNail()_

I don’t understand why it complains on ‘Loader’!?  
And what is the best way to access the instance of the ‘ThumbNail’ in the MouseEvent?

\*\*The .as file looks something like this : \*\*

```auto
package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.net.*;
    
    public class ThumbNail extends MovieClip
    {
        public var strFileName:String = "";
    
        public function ThumbNail()
        {
        }
        
        public function loadPicture(fileName:String) {
            strFileName = fileName;
            loading_txt.text = "Loading : " + strFileName;
            
            var imgLoader:Loader = new Loader();
            imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
            imgLoader.load(new URLRequest(fileName));
        }
        
        function loadComplete(e:Event) {
            var imageLoader:Loader = Loader(e.target.loader);
        
            //Scaling picture into a 60x60 image
            imageLoader.scaleX = 1 / (imageLoader.width / 60);
            imageLoader.scaleY = 1 / (imageLoader.height / 60);
            
            thumb_mc.addChild(imageLoader);
        }
        
        public function getFileName():String {
            return strFileName;
        }
    }
}

```

**and the actionscript in my main file :**

```auto
var imageArray:Array = new Array("Jag.jpg", "Eye.jpg", "Peo.jpg");

for(var i:Number = 0; i < imageArray.length; i++) {
    var newThumbNail:ThumbNail = new ThumbNail();
    newThumbNail.loadPicture(imageArray*);
    this.addChild(newThumbNail);
    newThumbNail.x = 70*i + 10;
    newThumbNail.y = 10;
    
    newThumbNail.addEventListener(MouseEvent.CLICK, clickedOnThumbNail);
}

function clickedOnThumbNail(e:MouseEvent) 
{
    var nail:ThumbNail = ThumbNail(e.target);
}

```

Any ideas??
