Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
friendlygiraffe

Loading SVG graphics with LoaderMax

Recommended Posts

Hi, I found a great library for loading external SVG graphics:

 

http://code.google.c...svgrendererlib/

 

It's very simple, using something like this code:

 

import com.lorentz.SVG.display.SVGDocument;
import com.lorentz.processing.ProcessExecutor;
ProcessExecutor.instance.initialize(stage);
ProcessExecutor.instance.percentFrameProcessingTime = 0.9;
var svgDocument:SVGDocument = new SVGDocument();
svgdocument.load('graphics/coloredtoucan.svg');
addChild(svgDocument);

 

I was looking at loading it using LoaderMax, but couldn't get anywhere with SWFLoader and ImageLoader.

 

Any suggestions no how I might achieve this?

Link to comment
Share on other sites

Ok I found a way round it, using DataLoader. It just fetches the raw SVG data and converts it to a graphic

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;
import com.lorentz.SVG.display.SVGDocument;
import com.lorentz.processing.ProcessExecutor;
//create SVG graphic
ProcessExecutor.instance.initialize(stage);
ProcessExecutor.instance.percentFrameProcessingTime = 0.9;
var svgDocument:SVGDocument = new SVGDocument();
//create a LoaderMax named "mainQueue" and set up onprogress, onComplete and onerror listeners
var queue:LoaderMax = new LoaderMax({name:"mainQueue",onprogress:progressHandler,onComplete:completeHandler,onerror:errorHandler});
//append several loaders
queue.append( new DataLoader("graphics/coloredtoucan.svg", {name:"childClip"}) );
//start loading
queue.load();
function progressHandler(event:LoaderEvent):void
{
// trace("progress: " + event.target.progress);
}
function completeHandler(event:LoaderEvent):void
{
svgdocument.parse(LoaderMax.getContent("childClip"));
addChild(svgDocument);
TweenMax.from(svgDocument,1,{alpha:0});
}
function errorHandler(event:LoaderEvent):void
{
trace("error occured with " + event.target + ": " + event.text);
}

  • Like 1
Link to comment
Share on other sites

  • 9 months later...

Hello,

 

I have the same estructure, but appart of this i would like to load svg by string, where the string is the svg text - tag itself, no the path of the file,

 

so instead of

 

queue.append( new DataLoader("graphics/coloredtoucan.svg", {name:"childClip"}) );

 

something like

 

queue.append( new DataLoader("("<svg ...../>",", {format:"text"}) );

 

try differents options, but no one works.

 

Someone knows if that is possible?

 

Cheers!

 

Link to comment
Share on other sites

If you have the text, there's no need to "load" it at all, so I'm kinda confused about your goal. LoaderMax is for loading external assets.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×