0

I have:

var current_image_;
var canvas_;

canvas_ = new fabric.Canvas('myid');
canvas_.renderOnAddRemove = false;


function LoadImage(path)
{
    fabric.Image.fromURL(path, function(oImg) {
        // Something
        current_image_ = oImg;
 });    

    Draw();
}

// Other things

function Draw()
{
    canvas_.clear();
    canvas_.add(current_image_);
    canvas_.renderAll();
}

current_image_ is Always a null reference. Why? In fact it doesn't render anything. I just want to try to render in certain times the Whole scene, but I felt in error.

Thanks!

Francesco Bonizzi
  • 5,142
  • 6
  • 49
  • 88
  • 2
    Move your call to "Draw" **inside** the callback to `.fromURL()`. – Pointy Apr 19 '14 at 13:49
  • @Pointy it works, but I don't understand why! – Francesco Bonizzi Apr 19 '14 at 13:51
  • 2
    @misiMe read the linked duplicates - that `.fromURL()` call is **asynchronous**. The call returns immediately, before the HTTP request completes. The callback is called *after* it completes, so at that point the image is ready. – Pointy Apr 19 '14 at 13:58

0 Answers0