SVG runtime load library - actionscript-3

Does anyone know of a good SVG loading library? I need to dynamically load in an SVG at runtime and display it to the user.
I've found two older libs that seem to cover some use cases:
https://github.com/lucaslorentz/AS3SVGRenderer
https://code.google.com/archive/p/svgweb/
but I was wondering if anyone know's of any maintained libs?

Related

How to "convert" a simple flash project to HTML5 using OpenFL

I have to "convert" some flash projects to HTML5/JS but I don't really know how I can do it :(
This flash projects are little "activities" like this one :
https://www.brainpop.com/artsandmusic/artconcepts/cameras/activity/#=standard
I did some research about it, but i'm a bit lost...
I found other people asking the same question and a lot of responses are to use Haxe/OpenFL and as3hx (https://github.com/HaxeFoundation/as3hx) but I don't really understand how to proceed...
Is it possible to load a .swf file with openfl-swf to create a similar .html file ?
Should I convert AS3 to Haxe3 with as3hx ?
Is there a simple way to just get a graphic render of this activities without any interactivity so I can add manually input text field ?
I never used ActionScript or Haxe before.
If someone has any suggestions i'll be glad to hear it :)
I hope my explanations are clear, english is not my first language, so excuse me for any mistake.
Cheers !
as3hx will convert only as3 code to haxe openfl and may well need hand tweaking. To make the code more flexible try to avoid extending Sprite then potentially it will be easier to use your activity logic in more webgl accelerated haxe solutions like Kha and Luxe.
You probably need clean seperation of the code and the onscreen layout.
To run a fla swf that is mostly graphics in openfl you need to use the haxelib https://github.com/openfl/swf, it can be quite fiddly getting to different children or frames and the gradients are not perfect, just remember when using it that it's not the same as accessing a child normally your using a structure that is a bit different to do that.
Alternatively you may find flump useful it can be used with openflump.
https://github.com/SavedByZero/openflump exports from flash IDE.
It converts lots of your graphics to png sequences in nested structures, it would probably be worth rebuilding textfields yourself.
Openfl js can be slow I suggest you do some tests before committing to a solution, since Kha or Luxe may provide you a more shader modern approach to graphics than a flash emulation api solution, but then all you assets largely need to be images.
I doubt if there is any ideal way but getting your logic in Haxe is really good idea because then you can do c++, c#, js etc.. The first step if you choose openfl is to perhaps to try just porting parts of your code to haxe and then use them as a swc in your current projects this will allow you to gradually check your conversion and fix an issues easily within a haxe flash approach prior to trying to do the same in html haxe. You may find the swf library is not ideal for html5 and that png's are the way to go, Animate now provides export png sequence which I have used in starling as3. Another approach to consider is the away3d plugin for Animate it can convert flash timeline into typescript away3d (2D ) that you can control with javascript code ( even haxe you may have got from as3hx if you remove some of the flash specific haxe and adjust it to work with the away3d 2d but I guess it could be very complex ).

Will embedding icons to CSS increase the swf size?

If I embed icons in the CSS file and refer to the style name in action script code, is that a good practice? Will that increase the swf size?
Any help would be really appreciated.
Thanks,
Gurjaspal
Yes, whatever way you choose, the font face will be embedded inside the SWF file.
Two ways to limit file size when using embedded fonts are :
Include only the needed character range. See this page for more information.
You can embed fonts in the main application and reference them in other parts of the application that are loaded later on (modules or their stylesheets)
Yes... Embed away. Flex has many built in compression algorithms that do a fantastic job of reducing file size. I've tried to optimize this process myself when building for web delivery and ultimately I could not get the file any smaller than flex could embedding the assets natively.
EDIT:
My assumption on adding this second answer is you were asking about icons (imagery) and not fonts.

As3 font embedding

I have seen lots of questions related to font embedding in flash and I can't seem to find an answer to my problem.
I load fonts from a font swf and register them at a high level so that they can be used in child swfs. The issue is the child swf might also embed these fonts, but not explicitly so, meaning they are only embedded because there are fields in the child swf that use certain characters of a font. This means the text fields in the child use the incomplete embedded font instead of the embedded complete set that is registered in the parent or any level of grandparent. Also this means the swfs that may become children of this child won't get the complete font.
My question:
Is there any way to tell flash at compile to not embed, under any circumstances, fonts into a swf? If not is there a tool that removes embedded fonts from a compiled swf?
Here's a few things I have given thought to/noticed so far:
It seems as if each Font class is tied to an ApplicationDomain. ( Confirmation of this would be helpful )
Using device fonts on text fields will not cause any fonts to embed. ( Not an option for me however because I need the fields to embed fonts at runtime from a parent swf. )
I can't find a way to unregister fonts or simply tell loaded child swfs to use parent fonts, which would be useful to apply to the loaded child swfs.
It may be possible to load the child in a different context that would allow parent definitions of a fonts to override the child definitions. ( Or would there be two definitions and if so which one takes priority? )
Loading assets from the library of the child and adding them to the stage will get the parent definition of the font. ( this makes sense because the asset is created outside the domain of the child )
A possible solution might be to not add any characters to the textfields for compile of the swf, but this isn't really an option either because I need static text using any font.
I've started forming a definition of what the problem is in my mind that may be incorrect, so please if necessary take a few steps back and give me a different perspective on the problem. So far it seems like the question I asked above is the right question to answer and if there is a solution to it, all my problems go away.
Thanks!
If I am right in understanding, than you want to remove/unregister all fonts that are not that complete as the version of this specific font that was already loaded, but embedded in another swf?
Every Font that is embedded creates a class, every swf you load via the Loader class is by default loaded in its own application domain, to prevent namespace clashes, but you can force the loader to load everything into the current application domain with the »loader context« parameter of the Loader's load() method. So this way you could try to force to override classes in the same namespace with each other, but than you cannot control which class to throw away, means you cannot check which font has more glyphs. (maybe it just throws errors instead of overriding and doesn't run at all, i am not that sure about this).
On the other hand you should question how fonts are actually embedded in the child's swf-files. I know no other way than to embed fonts as:
in *.fla-files as »library symbol«,
or in code of flashbuilder or flex like this:
[Embed(source="c:/windows/fonts/verdana.ttf", fontFamily="Verdana", embedAsCFF="false")],
or this:
#font-face {
src: url("../assets/MyriadWebPro.ttf");
fontFamily: myFontFamily;
advancedAntiAliasing: true;
}
in mxml files. So the (that is what I guess) the resulting Name of the class that is generated depends on the »font-family« property (or even more settings) given by the developer, means even if the same font is embedded twice the class-name might differ caused through the settings.
Also there is no Font.unregisterFont() method, so how to manage this stays a good question, just in case that you might find the same Font class somehow (perhaps RegExp becomes a friendly helper).
I think to solve this properly you need control at compile time, using xml based *.xfl project files might help but even than the referenced Font-File can have a different Name.
A nice problem, good luck
I had a lot of problems using fonts with flash. It is still a problem on html with different browsers rendering in different ways.
Anyways, for flash, I built this toolkit that helps me a lot. Check how to customize your fonts. If you do the steps I am pretty sure the problem will be solved.
https://github.com/tbwa/AS3-Toolkit/tree/master/src/com/utils/text
Turns out this is an bug with my version of Flash Professional. I did an update and runtime shared fonts are now possible. I will probably point the shared font at a bad url for the fonts then the fonts will come from the parent application domain because they aren't compiled into the child swfs. I'm using Flash Professional CS5.5 11.5.1 now. I was using CS5.5 11.5.0.
http://forums.adobe.com/message/3926344
Thanks Adobe for wasting my time.

How do I make a custom Flash component work with any font?

So we have a component we have written ourselves that deals with text display and translation between languages, reading translations from a file. Ideally what we would like to do is have this component be compatible with any font we can embed in the main .swf's library. What's the best way to do that?
Currently we are going down the route of having our component have an attribute for the font name, lets say 'Font1'. We drag the component into the .FLA file we want and then add a new font to the library called 'Font1' and set it to the typeface we want. This is proving to be inconsistent and problematic which implies it's not really an ideal way of doing it.
Is there anyway to achieve the feature we want? The key is flexibility, we want to easily support languages (hence the component) but we don't want design to be limited in their font selection. Its not practical to embed a range of fonts in the component for example, as it adds to file size and is restrictive.
Any ideas or solutions to this much appreciated. The component is written in AS3 and we are using Flash CS4.
Look into Runtime font loading or runtime font embedding.
There are many ways to deal with this depending on your development environment. In that regard, FlashBuilder may offer you more flexibility than Flash CS4 actually.
A general approach could be to have a set of SWFs file, each embedded with a particular font. Of course, these SWFs shouldn't be loaded at start up.
When calling a font in your component, you would practically call a function that would load the corresponding SWF, adding the font to your Application Domain, therefore making it available to your component.
Here's an article that may help in clarifying the process
http://nochump.com/blog/archives/20
but a Google search such as Runtime font loading or embedding should bring out a lot more resources.
Hope this helps!

Optimizing AS3 SWF files for size?

Are there any tips / best practices / secrets for optimizing the size of AS3 SWF files? In particular, any way to get a breakdown of what is taking up space inside the SWF, like you used to be able to in the old Flash 7/8 days? I'm not using the Flash IDE any more, but now I'm using either Flex Builder or FlashDevelop, so it needs to be something that I can do without the Flash IDE.
If you're interested what in the code is taking up space, you can get that information from the link report. It's not as detailed as what you can get out of the Flash IDE, but it shows the size of each class (uncompressed.)
To create a link report, use the -link-report <filename> flag on mxmlc. It creates an XML file with information about the classes linked into your SWF.
I used the .XSL file described in the link below to clean it up and make it more readable:
http://blog.iconara.net/2007/02/25/visualizing-mxmlcs-link-report/
One tip would be to try Joa Ebert's "Reducer" tool which can greatly reduce the size of any PNG files in your SWF if you used the embed tag.
http://blog.joa-ebert.com/2009/08/08/reducer/
Make sure, you use PNG-8 where it is possible and PNG-24 where you need alpha-channel.
Use pngout tool to optimize them.
And there are some tools that can obfuscate and optimize SWF files.
I'm not sure what can be done with Flex Builder or FlashDevelop but what I always watch out for is font embedding. I take care to embed only the characters which will definately be used in the final swf.
Hi I previously posted this link in a related question about link report analysis (here), I've used this in the past and its quite a nice tool
LinkReportAIR