Flex embed dynamically - apache-flex

In one project, I have several similar applications, they just differ slightly here and there. Like some of the contained icons/images. To help organizing, I see myself [Embed]ing icons in a style like below, however the use of variables in the [Embed] metatag doesn't work.
The below code is contained in a custom component, so I easily should be able to set different icons per application including the component. How do I get around this problem?
public var iconBase:String = "/icons/red/";
[Embed(iconBase + "play.png")] [Bindable] public var icon_play:Class;
[Embed(iconBase + "stop.png")] [Bindable] public var icon_stop:Class;

This should answer your question: Embedding sources dynamically.
Metadata is pre-processed by the compiler, so you can't have any variables in there.
Hope that helps,
Lance

You have quite a few options:
Write a quick code generator to
build the appropriate source files.
Load the icons at runtime, that
way you could change the paths.
Use symlinks to change where the
icon files are retrieved from.
Make an icon library or module and
either load them at compile time or
at runtime.
I think I would just load the images at runtime and change the base path.

One option is to use the ResourceManager and put embed statements in resources files. Different apps could define different resource bundles.

u could use
btn.setStyle(“icon”,iconSymbol);
it can help

Related

How to use own icons in Flet

I can't find how to load my own icons in Flet.
I'm testing Flet with the intention of making a desktop app (pure desktop, not Internet needed), but I'm not able to use my own icons to begin with. I can only use the ones that come inside ft.icons, but I'd rather use my own by loading them from a folder similar to /assets/icons. Can I do that? How?
Thanks.
Currently, I don't see a way of doing this; however, you could use the Image class instead.
I would suggest you create an assets folder under your main project folder.
Let's assume you have the following folder structure on your project:
/assets
/icons/my-icon.png
main.py
When you are running your app, you should provide that folder to the initializer in the following way:
flet.app(target=YourApp(), assets_dir="assets")
Then you can access your images there directly and create an Image instance in the following way:
test_image = flet.Image(src="icons/my-icon.png", width=32, height=32, tooltip="Image Tooltip")
You can nest these Image controls inside of anything you want, so you have a lot of flexibility.
The only downside of doing it this way is if you are using light/dark themes on your app. Compared to the Icon class, you will have to specify the light/dark theme versions yourself and update them manually when you are switching your theme.
Here is the official documentation

Theming HTML5 canvas along with rest of site

I'm working on theming a web app, and I ran into a problem with an angular directive that is being used. It's called angular-knob, and it uses an HTML5 canvas to display a progress bar input. Since it's a canvas, you have to tell it the color in JavaScript instead of CSS. This is the problem.
The rest of the site is themed based on a set of LESS variables. I would like the canvas to be the color of #brand-primary from the variables.less file, which could also be overridden in other theme-*.less files. I haven't found a good solution to this yet, but these are some of the ideas I've had:
Parse the variables from the LESS file with some kind of ASP.Net utility (haven't found anything that would do this for me) to get the variable names and then render them to the client in a JavaScript variable (which I could then put in an angular service)
Have gulp parse the variables from the LESS file (again, haven't found any npm packages that would do this for me) and create a script that puts the variables in with the JavaScript bundle.
Like I said, I haven't found any LESS file parsing utilities for ASP.Net or npm that would get me access to the LESS variables.
How would you tackle this kind of problem? Has anyone else had to handle something like this?

Unable to use playn JSON classes in Eclipse

I'm not able to access the playn.core.json.* classes inside eclipse even though everything else works in general. I have used this http://code.google.com/p/playn/wiki/GettingStarted in setting up my eclipse project.
However the following classes are visible -
JsonImpl
JsonParserException
JsonSink
JsonTypedArray
JsonWriterException
When I go to the referenced libraries in Eclipse, I can see playn.core.json and
can see all classes inside it. I'm just not able to use them inside my
code.
Thanks!
Just saw the samples.
You're supposed to use the interface Json.Object/Json.Array.
Use PlayN.json().createObject() to create a new Json.Object instance, and PlayN.json().createArray() to create a new Json.Array instance.
Make sure you have statically imported playn.core.PlayN.*

How to open mxml file from other mxml file?

In my flex 3 application, i am maintaining two mxml files say one.mxml and two.mxml. How can i call two.mxml from one.mxml. I don't want to use any variables from different mxml files. I want to redirect it. How it can be? Thanks in advance
Try this
var pop:mxmlFileName= mxmlFileName(PopUpManager.createPopUp(Sprite(Application.application),mxmlFileName,true));
PopUpManager.centerPopUp(pop);
I stumbled upon this while debugging a project I am working on. Not sure if it is optimised anyway but it should work.
you can simply create an instance, then add it to stage:
var one:One=new One();
addElement(one);
but don't forget, one.mxml must not be an application, only a component. if it is so, you have to reedit the main node of the mxml.

Flex AS3 Project Convert to CS4

Has anyone got experience in converting AS3 projects (no mxml) in Flex, to Flash CS4? Are there any resources out there as to what works in Flex Builder that doesn't work in Flash, and how to get the project running? I read somewhere that (for instance) certain Metadata tags don't work.
If I've got all my code in the src folder, should I just create the .fla file in that folder and basically copy all code from the .as file which launched the Flex project? Or create the .fla file somewhere else and point assign that src folder in the classpath? Also, not being familiar with the CS4 IDE, do I create a new Flash Project?
Thanks!
So here's the issue I'm having. The code in the Flex AS3 looks like this:
[Embed(source='C:/WINDOWS/Fonts/ArialBD.TTF', fontWeight = 'bold', fontName='ArialBold', unicodeRange='U+0020-U+0020,U+0021-...')] //a bunch of other unicode
public static var _VerdanaFontBold:Class;
[Embed(source='C:/WINDOWS/Fonts/Arial.TTF', fontWeight = 'regular', fontName='Arial', unicodeRange='U+0020-U+0020...')] //a bunch of other unicode
public static var _VerdanaFont:Class;
And in constructor of the extended textfield in which my text appears I have:
Font.registerFont(_VerdanaFontBold);
Font.registerFont(_VerdanaFont);
CS4 doesn't allow use of the Embed metadata. So I've commented that out. In CS4, I understand that I'm supposed to create a blank textfield in design mode, which I've done. I then can select fonts to embed. I've selected verdana (upper and lower case, punctuation, number, etc).
When I run the app in CS4, the textfield is blank.
What am I doing wrong? Do I need to give the verdana font an instance name of _VerdanaFont? I wouldn't think so, since I've had to comment out the Font.registerFont as well. The fact that I'm embedding the font in a blank textfield, and not the one that's called by the document class I've set, shouldn't matter, right -- the font should just be embedded in the swf and available for use. But it's blank.
Does anyone know what to do here?
Edit: Well given that the apparent reason this isn't working now has to do with fonts not showing up correctly, I better create that as a new Question. Also, there's a clearer description than the one in the link provided above regarding the document class, here: http://www.heaveninteractive.com/weblog/2008/03/04/introduction-to-the-document-class-in-actionscript-30-tutorial/
It really depends. If it's just a pure AS3 project that relies only on playerglobal.swc it should be fairly easy. Just copy your .as files and add them to your new project as Cameron has suggested.
If however you've written a pure AS3 Flex app that relies on any of the other SWCs (flex.swc, framework.swc, etc) it's not really possible, as CS4 can't use SWC files. If you google around you might find somebody who's disassembled the SWC into various .abc files and a SWF full of resources, but you'll probably end up having to embed the entire Flex framework and all support code into your final SWF, which will bloat it big-time.

Resources