How to open mxml file from other mxml file? - apache-flex

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.

Related

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.*

Flex 4 Get loaded modules StyleManager

I've a multi-module Flex 4 application. It's PureMVC modelled and during one of the startup commands it attempts to get a style. However, with Flex 4's new StyleManager per module approach, I can only get a reference to the topLevelApplication's styleManager which doesn't have the styles loaded that are loaded in the module.
I've scoured the web for a solution to this but to no avail. In a number of places the suggestion is to get the module and from it get it's factory which will allow me to
var info:IModuleInfo = ModuleManager.getModule("<filesystempath to module swf>");
var sm:IStyleManager2 = StyleManager.getStyleManager(info.factory);
which does indeed seem to give me back the correct style manager, however, it's got to be wrong because I can't be having to get the module and from it the StyleManager everytime I want to get a style for something in the code?
I would have hoped there'd at the very least be a ModuleManager method which I could supply the simple name of the swf as opposed to having to cart around the absolute path?
So my question is, from within code in a module, how does one get a handle to the Module specific StyleManager?
Thanks for your time,
Mark.
Well as far as I remember, in a Flex4 UIComponent you allways have a property styleManager that automatically references the current modules styleManager.

Flex Builder: Not picking up new files

I have a working AS3 project and it compiles fine to a SWF. I added a new file (via various means: import, drag-drop, new), but it doesn't compile this new file. I'm using Flex Builder 3. I've tried a clean an rebuild. I've tried renaming. It picks up the existing files fine, but not the new one. The project is set to use a HTML wrapper. I see some build files (I think). The new file is in an existing folder and package.
Any idea what could be wrong?
First, the SWF Compiler will optimize your end code. If you never use a class or create an instance of it anywhere in your application; that code will never be compiled in your application. this is a common occurrence if you're using Flex Remoting with some backend; and a VAlue Object is never instantiated directly, instead you're always returning arrays of it. You'll find you get a lot of "Generic Objects" without the backend object-to- AS3 object translation of the Flex Remoting Gateway.
You didn't specify what type of file you are adding. If it is an ActionScript file it won't automatically be compiled in the swf. You'll have to 'include' it in another class somehow. IF it is an ActionScript class or MXML Component, make sure you are using that class somehow in your code. If it is another file type, such as an image or other asset you'll have to embed that file into your code somehow.
We might be able to offer more help if you were to tell us what type of file is not being added to the final SWC. Also tell us how you can tell.

FLEX components: updating import statements to move the component into another folder

I've just imported a Flex component into my project.
I have a theory question about importing.
all the imports statements in the component source files started with "com.subFolder.etc", but I have preferred to move the component folders into "componentName" and to replace all import statements as "componentName.com.subFolder.etc"
Is this ok ? Everything works perfectly, but I was wondering if the method is correct.
thanks
You can put the components anywhere you like, however you want to organize them. People will site best practices and theory but if you know where everything is and you tell the compiler where they are:
import componentName.com.subFolder.componentToBeUsed;
Everything will compile and run just fine.
Usually you will see code and components broken up in a domain model.
So you'll have:
com.yoursite.views
com.yoursite.events
com.someothersite.renderers
Which correspond to:
/com/yoursite/views
/com/yoursite/events
Basically all of your code living in folders within /com/yoursite/
and:
/com/someothersite/renderers
being a custom renderer you imported from someothersite.com to use in your application.
In the end, for the compiler and the flash player I don't think it matters where you put things as long as your happy and understand it all...and of course 6 months from now when you come back to look at this code!
It's totally correct, yes.
Note that Flex Builder (if you're using it) can automatically replace your import statements/class name when you rename a directory or a .mxml/.as file.
I never tried moving a complete structure, though, but I would't be surprised if it worked too.

Flex embed dynamically

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

Resources