You'll understand right away when you see the screenshot. I just realized I can move the rectangle, however, it will be useful to know how to position and control the size of the bitmap for some things I'm going to do later. I.e. how to set x, y position, width and height.
Thanks for the list of links, that's a treasure trove of information. I saw just now there are videos on your Youtube channel that goes into exactly what I'm going to do soon. I'm eternally grateful.
Nice! You're welcome.
So here is another sample that should be closer to real world requirements.
JS / JavaScript code:
var root = this;
var startX = 8;
var startY = 8;
var offsetY = 8;
var iconHeight = 24;
var imgsrc="https://www.google.com/s2/u/0/favicons?domain=scmp.com";
var librarySymbol = lib.IconContainer; // "IconContainer" is the symbol linkage name in the Library
var data =
[
{ src: imgSrc, symbol: librarySymbol, text: "Icon 1" },
{ src: imgSrc, symbol: librarySymbol, text: "Icon 2" },
{ src: imgSrc, symbol: librarySymbol, text: "Icon 3" },
{ src: imgSrc, symbol: librarySymbol, text: "Icon 4" },
{ src: imgSrc, symbol: librarySymbol, text: "Icon 5" },
{ src: imgSrc, symbol: librarySymbol, text: "Icon 6" },
{ src: imgSrc, symbol: librarySymbol, text: "Icon 7" },
{ src: imgSrc, symbol: librarySymbol, text: "Icon 8" }
];
function main()
{
var i, iconContainer, img;
document.body.style.backgroundColor = "black";
for (i = 0; i < data.length; i++)
{
iconContainer = new data[i].symbol();
iconContainer.x = startX;
iconContainer.y = startY + i * (iconContainer.nominalBounds.height + offsetY);
iconContainer.txt.text = data[i].text;
root.addChild(iconContainer);
img = document.createElement("img");
img.src=data[i].src;
img.container = iconContainer;
img.onload = function(e){ loaded(e.target); };
}
}
function loaded(img)
{
var bmp, bounds;
bmp = new createjs.Bitmap(img);
setBitmapHeight(bmp, iconHeight);
bounds = bmp.getTransformedBounds();
bmp.x = startX;
bmp.y = (img.container.nominalBounds.height - bounds.height) * 0.5;
img.container.addChild(bmp);
}
function setBitmapHeight(bmp, newHeight)
{
var originalHeight = bmp.getBounds().height;
bmp.scaleX = bmp.scaleY = newHeight / originalHeight;
}
main();
FLA download:
https://bit.ly/3HM2A6Q
I hope this helps.
Regards,
JC