Skip to main content
thomasw72287590
Inspiring
April 14, 2017
Answered

Access images within the library

  • April 14, 2017
  • 2 replies
  • 718 views

I need to be able to access the actual image from the library so I can do this:

function drawShape() {

    console.log('draw shape');

    overlay = new createjs.Shape();

    stage.addChild(overlay);

   

    overlay.graphics.clear()

        .beginBitmapFill(img)

        .drawRect(0,0,800,600);

  overlay.cache(0, 0, self.canvas.width, self.canvas.height);

}

var img = new Image();

img.onload = drawShape;

img.src = "test.png";

Do anyone know how to grab the image from either the library directly or from an MC holding the image?
Just to be clear I need to the actual image file so I can manipulate it directly. Simply loading an MC containing the image or loading the image via linkage will not work. Not unless I can use either of those to grab the image.

This topic has been closed for replies.
Correct answer ClayUUID

I think this may do what you want:

In the library, give the bitmap a linkage name (double-click in the Linkage column next to the bitmap's name).

var myImage= new Image();

myImage.onload = drawShape;

myImage.src = img.myTestLinkageName.src;

DO NOT create any variables named "img". That name is used by CreateJS to hold the collection of all loaded bitmaps.

2 replies

thomasw72287590
Inspiring
April 14, 2017

I'll give it a try tomorrow. Thanks for the help on this

ClayUUIDCorrect answer
Legend
April 14, 2017

I think this may do what you want:

In the library, give the bitmap a linkage name (double-click in the Linkage column next to the bitmap's name).

var myImage= new Image();

myImage.onload = drawShape;

myImage.src = img.myTestLinkageName.src;

DO NOT create any variables named "img". That name is used by CreateJS to hold the collection of all loaded bitmaps.

thomasw72287590
Inspiring
April 14, 2017

Good point about my naming. Thanks.
img.myTestLinkageName.src returns Cannot read property 'src' of undefined

and I think Im calling everything correctly:

987b8b44b0392d4e489227c223bad0c3.png

Legend
April 14, 2017

I just tested using the exact code you posted, and it worked fine. Are you sure you haven't overwritten img anywhere else in your code? Try doing a console.log(img);