Skip to main content
Sebas tian
Participant
May 19, 2023
Question

Load or Draw a SVG with javascript

  • May 19, 2023
  • 1 reply
  • 349 views

Hello everyone! 

I'm working with some images and need to load dynamic SVG to show some graphics shapes, but I found this is not possible natively, so I'm looking for options. 
I can't import the SVG to the FLA, also use transparent MPG or GIF to dynamic load results on tons of files and a huge size increase. 

note: all my SVG are composed only with Path objects. no polygons, and no simple shapes. 
I tried to draw the paths of SVG using Path2D() but it draw only for a fraction of a seccond and then disapears. 

Anyone has tried to draw or import SVG, I have no idea other options, besides change the framework  

Thank you for reding 

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    May 20, 2023

    why can't you import an svg?

    Sebas tian
    Participant
    May 22, 2023

    Thanks kglad, 

    I'm trying to make a dynamic project. witch load different content maintaining the main structure. 
    I would like to avoid editing the FLA just to import files to the project if those files can be loaded dynamically 

    kglad
    Community Expert
    Community Expert
    May 22, 2023

    you can use preloadJS, https://createjs.com/docs/preloadjs/modules/PreloadJS.html

     

    eg,

     

    displayPicture('./images/svg_file.svg');
    var tl = this;
     
    function displayPicture(imgPath) {
    var image = new Image();
    image.onload = onLoadF;
    image.src=imgPath;
    }
     
    function onLoadF(e) {
    var img = new createjs.Bitmap(e.target)
    tl.addChild(img);
    stage.update();
    }