Use Flash as shell to load Flex app and pass URLVars? - apache-flex

I am having a problem with preloaders showing up in my flex apps. I never had this problem when developing flash apps so I got the idea to use a flash app as a shell with the sole purpose of showing a preloader while the flex app loads. I am not sure how to do this though, and I also need to ba able to pass the FlashVars from the shell flash app to the flex app. Does anyone know how this can be done?

Flex supports preloaders through the Application class, so you shoudn't have to resort to a hack. It's described in detail in the Flex 3 Developer Guide, Ch. 14 ("Application Container"). I never programmed a pure Flash preloader, but I figure it's different from what Flex does. Maybe the two of them conflict?

I am going to begin by agreeing with Simon, but there are ways to create the hack you're talking about.
Unfortunately, the parent layer to the Application in Flex overrides numChildren so that it always returns -1. This means that you are neither able to access the parent swf from flex, nor are you able to directly access the descendant SWF from Flash (amusingly, if a Flex App loads a Flash swf, this is not a problem).
The way around this:
Create a custom event. Set bubbling to true and cancelable to false.
Add an event listener for that event on the Flash layer.
Dispatch that from the Application layer of the Flex App.
The function which handles that event can now use the target property of the event to access the Application layer of the Flex App.

Related

Swiz framework with AIR - Using ViewAdded/ViewRemoved on child windows?

I'm trying to implement a popup window (NativeWindowType.UTILITY) in an AIR 2.7 application that uses Swiz for dependency injection.
I have followed the Swiz guidelines that I've been able to find, and implemented ISwizAware on the class that creates the window, and I am calling _swiz.registerWindow() before opening the window, and dependency injection works fine on the window itself after this.
However, the problem I am running into is that I have a child view within that window, and I have a mediator that uses the [ViewAdded] and [ViewRemoved] tags. Neither the view added nor view removed functions are triggering. I'm thinking the issue is either:
The child view is not correctly registering with Swiz.
The swiz instance doesn't know about the beans (I have tried manually adding the bean however, which didn't have any effect).
The ViewAdded and ViewRemoved metadata tags simply aren't working because each NativeWindow object has its own stage instance.
Anyone know more about this?
Popups are a special case since they don't get added under the same display tree as your application. Under Stage (the main wrapper for Flash Player), you'll have Application where your code resides for Swiz, but Popup is in a separate layer above Application. Since they're siblings, Swiz cannot listen in for when the popup is being added to the Stage.
The way around this is to either set the properties of the popup manually (which is normally the easiest way) or manually add the popup to Swiz's awareness. For this you'll have to look at the documentation since I haven't touched Swiz in a long time.

What's the Flash equivalent of FlexEvent.CREATION_COMPLETE

I'm moving some Flex classes to pure Flash/AS3 to be part of a shared library. I have an event listener on FlexEvent.CREATION_COMPLETE to create and add display-objects once things are running, but I don't know the right way to do this in Flash?
edit: Maybe if my class subclasses Sprite rather than a Flex class, I can add children in the constructor, I don't need to wait for a "construction complete" event?
It depends on what you are trying to do: When you add children in the constructor, you will not be able to depend on any information about the stage and/or other elements on it. I have found it a better practice to add an event listener for Event.ADDED_TO_STAGE in the constructor, and have the handler method initialize the element.
You're really comparing apples and oranges here.
The Flex Framework is a UI Framework, and the CREATION_COMPLETE event is part of that framework.
Flash Professional is an IDE, primarily geared for creating animation. It has ActionScript support, but is not a framework and does not offer anything beyond native ActionScript other than libraries or classes you build, buy, create, or borrow.
If you want some parallel to creationComplete, you'll probably need to find--or create--a UI Framework. It is, in theory, possible (although not easy, nor something I'd recommend) to initialize the Flex Framework for use inside a Flash IDE created movie. After all, under the hood it is all ActionScript.
creationComplete Dispatched when the component, and all of its child components, and all of their children, and so on have been created, laid out, and are visible.
See more info on the flex life-cycle events and some that are plain flash here: also +1ed the added_to_stage as it's likely what you'll need in this case.
http://livedocs.adobe.com/flex/3/html/help.html?content=containers_intro_3.html

How to pop up Flex Panel by clicking on a GWT(or GXT) component?

I have a web-application whose UI is implemented in GXT (ext GWT).
Now I want to switch to Flex but as the application is so large that I cannot afford to start migrating the whole application at once.
So I have decided to migrate slowly. So what I want is to bring up a Flex panel on the click of a GXT's button.
Basically the idea is how to make Flex components listen to the events generated by GXT's component.
Flex app is ultimately an SWF and GWT gives you JavaScript; you can use ExternalInterface to invoke an SWF's methods from JavaScript code and vice-versa. Checkout the addCallback method - the linked page has some sample code in it.

a question about flex preloaders

I'm moving to a pure as3 environment into flex and I have a question about preloaders.
For one of my apps in particular when the swf loaded I would add a screen with an animated preloader. Then at a particular point in my code when I know all of my xml has been parsed, UI built and all initiliztion done I dispatch a "done" event which removes the preloader.
How can I achieve this is flex? I've only ever really seen flex preloaders that are percentage based which I believe represent the actual loading of the swf itself?
Please read the flex cookbook for preloaders, they have some demo applications, that could help u out
actually there is a preloader property in the application tag,
that could be wht u might help u out
tc
Ankur Sharma
Flex has a ProgressBar control that you can use for similar purposes. If you want to continue to use your own custom animated progress bar, you can add that Sprite to the rawChildren of a Container (preferably Canvas) and show it as a modal pop-up using the PopUpManager - remove the pop-up from the done event's handler.
The overriden addChild method of the Container class will throw an error if you pass a child that doesn't extend UIComponent - that's why you should use rawChildren.addChild.
Yep default flex preloader represents the loading of the swf itself.
If I were you, I would use the Task library from the Cairngorm 3 Libs, works perfectly with a preloader :
http://opensource.adobe.com/svn/opensource/cairngorm3/trunk/libraries/TaskTest/src/samples/TaskFlowPreloader.as

How to get the width and height in ActionScript for a Flex application running inside the flash player in the web browser

Does anyone know how to get the width and height in ActionScript for a Flex application running inside the flash player in the web browser.
e.g. In the web browser I can use the tag to embed a Flex application (as a .swf). To the embed tag, I can provide the dimensions. I would like to get these dimensions inside the flex application action script.
Thanks in advance,
Regards
Vivek
As of Flex 4.0, Adobe recommends using FlexGlobals.topLevelApplication instead of Application.application.
Depending upon what you are doing, you can look into using stage. But, if you do, be aware that the stage will grow to contain movie clips that go outside of the bounds of the application. So the stage is frequently larger than the actual application.
I Flex you can access Application.application.height and Application.application.width.
You can use stage.stageWidth/stage.stageHeight. Be sur to call that from a DisplayObject that is on the display list or else stage is going to be null. It works for both Flex and Actionscript projects.

Resources