Skip to main content
Known Participant
July 22, 2009
Question

Bitmap

  • July 22, 2009
  • 2 replies
  • 588 views

Hello guys !

I have an issue with Bitmap object. I have a photo gallery which I read from an XML file. Each photo has a path, id and description.

When I'm adding the picture to the screen I am doing as follows:


var content:Bitmap = Bitmap(loader.content);

var subContainer:MovieClip = new MovieClip();


subContainer.addChild(content);

My problem is that when I click the bitmap added to the container I must know what picture this is by getting an id. This way I know what gallery I am to open. A bitmap object does not have this property to be set (id and path). I have decided to create a class which extends Bitmap and then add these attributes within this class. So instead of using a bitmap I would use something like:

var content:Picture = new Picture(id,path,Bitmap(loader.content));

subContainer.addChild(content);

Where Picture would be that class with path and id attributes. So when I click image I could get by event.target.id the source and hen take a decision of what gallery to open.

However, this is not working. It returns converson type error.

Can someone help me ??

Thanks !!

This topic has been closed for replies.

2 replies

susrut316
Participant
November 15, 2009

Hey check by adding a properties using getter/setter. Try with the code below:

package components
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;

    public class Picture extends Bitmap
    {
        private var _id:Number = 0;
        private var _path:String = '';
        public function Picture(bitmapData:BitmapData=null, pixelSnapping:String=auto, smoothing:Boolean=false)
        {
            super(bitmapData, pixelSnapping, smoothing);
        }
       
        public function get id():Number
        {
            return _id;
        }
        public function set id(value:Number):void
        {
            _id = value;
        }
        public function get path():String
        {
            return _path;
        }
        public function set path(value:String):void
        {
            _path = value;
        }
       
    }
}

November 15, 2009

go with susrut316's post.

you clearly have an understanding of classes, and adding properties to movieClips is a poor idea in as3.

kglad
Community Expert
Community Expert
July 22, 2009

if you create a new movieclip parent for each bitmap, add whatever properties you want (like id and path) to the movieclip.