Bitmap
Copy link to clipboard
Copied
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 !!
Copy link to clipboard
Copied
if you create a new movieclip parent for each bitmap, add whatever properties you want (like id and path) to the movieclip.
Copy link to clipboard
Copied
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;
}
}
}

Copy link to clipboard
Copied
go with susrut316's post.
you clearly have an understanding of classes, and adding properties to movieClips is a poor idea in as3.

