Get Fscommand in Flex3 - apache-flex

I have one swf file in that i used fscommand to get final output when submit button clicked in that swf ,
i am loading that swf in SWFloader in flex3 .i need to get fscommand value as Alert, how to get that value first and display as alert.
Thanks in advance

fscommand cannot be used for communication between loaded and containing SWFs.
From livedocs
fscommand: Lets the SWF file communicate with either Flash Player or the program hosting Flash Player, such as a web browser. You can also use the fscommand() function to pass messages to Director or to Visual Basic, Visual C++, and other programs that can host ActiveX controls.
You can call a method in the loaded swf OR access its properties directly OR use events OR use local connection to pass data between parent and loaded SWFs.

TECHNICALLY this is feasible, but a bad idea. You'd need to register a callback which would call the child swf (generally done from the child swf). But, you will risk a good deal of headache, and you'll have to rely a lot more on the browser than other options. It would also be slower than an AS only solution.
You're much better off (in this order):
Using a shared Singleton. This allows for complete separation of the two
swf's without requiring any major coordination between the two. The only
real potential problem can be caused if you want the child swf to have its
own ApplicationDomain, but even with that, there are work-arounds
Using events. This can work if you have the child swf dispatch a bubbling,
non-cancel-able event and have the event.target recorded by the
parent swf. You may have to adjust to avoid
SecuritySandboxViolations, however.
Using LocalConnections. The two detriments to LocalConnections are:
You will need to continually re-generate unique connection names to
avoid the error thrown by connecting two LocalConnections to the same
channel.
LocalConnections do have bandwidth limitations which can call
slowdowns if there is a high volume of traffic or if the messages are
too large.
Using direct manipulations like loader.content.foo.bar.baz;
I don't like this solution because it is much harder to maintain. It is
also much worse from a design perspective: you want to use
encapsulation as much as possible in this situation -- this technique
actively works against that.

Related

How to reduce SWF filesize by optimizing the code?

Considering we have already done the following actions:
Flex Framework as RSL
Compiling with debug=false
Loading most images at runtime
Drawing other simple images with flash draw features
Reducing complex images with pngquant
Creating modules for secondary features
Applying ranges to fonts
Running FlexPMD to find dead code and bad copy-paste
Running FlashOptimizer and secureSWF (with poor results)
Today our application is 1358k:
Code: 978k - 72%
Images: 270k - 20%
Fonts: 110k - 8%
We believe we spent a lot of time into asset optimization and most of the work is remaining on the code.
By analyzing our link-report, our guess is that the heavy part of the code is comming from Flex .mxml nested components. We don't think there is much to do on our pure AS classes.
Is there any analysis or coding best practice in order to reduce the impact of the code on the swf filesize ?
Thanks.
Here is the application : http://www.pearltrees.com/nicolas/137698/
In my practice I usually don't have big final swf files, so I want to mention only one thing. Using mxmlc directly we should not forget to add (for the final build of course) parameter/attribute
debug = "false"
in other way final swf will be almost 2 times bigger.
do you have an objects in the .mxml that are similar to each other that you could turn into a generic class and customize programatically?
Consider looking into preloaders and modules.
Without knowing your application, it's hard to be specific, but a custom preloader can sometimes help a lot with perceived download time. Let's face it, asking the user to idly stare at a progress bar is sad, and you can do better.
The usual example here is that your need your application users to login, or select some basic details before jumping into the main application. By implementation that first form as a preloader, your application will keep downloading in the background while your user interacts with that form.
The downside: Your preloader code doesn't have access to all the Flex goodness. You'll have to draw your UI and implement your interaction in plain old AS3. Still, the extra work can be worth it in some situations.
Flex Modules are the other thing that'd be worth looking into. In a complex Flex app, not everything is commonly used. If you cut the lesser-used bits from the main application and move them into a module you load on-demand, you may be able to save a fair amount of bytes from the initial download size.

How to mute entire flex application?

I'm playing several video streams in my flex application. Plus there are sounds of application UI. Is there possibility to mute entire application or I should silence each of potential sound sources?
Have you tried
SoundMixer.soundTransform = new SoundTransform(0, 0);
I'm pretty sure there is no way to do that with ActionScript out of the box. You'll need to have some manager class that keeps track of all the sounds (Sound, SoundChannel, SoundTransform, etc and your video streams) in your application and that has logic for muting.
If you can force your users to use firefox, there is a plugin available to mute swf files. Mute Flash - https://addons.mozilla.org/en-US/firefox/addon/5453
You probably have to re implement your app to centralize the control of audio components within your app. There is a design pattern out there called Inversion of Control that may be useful for this problem.
http://en.wikipedia.org/wiki/Inversion_of_control
Specifically with Flex, you should lookup the Model Locator pattern with Cairngorm.
http://www.adobe.com/devnet/flex/articles/cairngorm_pt2_06.html
You could use this to store all the various audio levels for your application in a single location. And you could add a method called muteAll() that would go in and set all the levels to 0. Anytime you create a new audio component in the app make sure to add a reference to its volume level in the model locator. Bind the audio's volume level to the value set in the model locator. Then elsewhere in the app you can change the value in the model locator and through binding the audio component you build will get updated.
This might also be helpful.
http://livedocs.adobe.com/flex/3/html/help.html?content=Working_with_Sound_23.html#160274

What restrictions/workarounds are needed for third parties external swf

We are loading external swf content into an adobe air application. Content is provided by an increasing number of third parties.
Being third party content, it will be loaded in a separate security domain (trustContent=false) and a sibling app domain (loadForCompatibility=true). We are doing this using the Loader class.
What are the features/options/approaches that would cause problems when using the swf as external content?
I am interested in any kind of issues, as we have already reproduced issues with content that occur regardless of the app domain / security domain where its loaded ( and occurs also in both Loader and SWFLoader).
Any workarounds for the issues are highly appreciated, especially ones that can be applied from the main app.
The big nasty problem (and one we've dealt with a lot!) is the fact that external SWFs simply can not be directly trusted. Ever. This makes communicating between them and the base AIR application difficult at best.
There is a hack around this based on loading the data of the SWF via a URLLoader and then taking the bytearray from it and pumping it into a Loader. However, I believe that hack was killed with AIR 1.5.1.
That being said, it is possible to communicate between the AIR app and the loaded SWF through what Adobe calls the sandbox bridge. However, setting up the sandbox bridge is a royal pain and any complex data (objects, even as simple as Arrays) get stripped down to generic objects on the other side of the bridge and can not be cast back to their original form.
For our recent projects that needed to use the bridge we created a specialty class called AIRBridge that you use on both sides of the bridge and it facilitates setting everything up properly. If you're interested, you can pull the current source from our Google Code project Automata-Tools.
One we already addressed:
Content outside of the external swf stage shows in the application, and when setting the size where it will be displayed the offstage elements are taken into account. Workaround: Add a mask on the main app so the external content is hidden. Use .content.width/height (full with offstage elements) and .content.loaderInfo.width/height (original stage size) to calculate how much to scale content so the original stage matches the visible area.

Difference in building swf through FlexBuilder and mxmlc(ANT build)

Will there be any difference between the swf generated by Flex Builder and mxmlc?
In my application, there is a page with certain fields to be filled in. Upon clicking a button, it opens up a popup. Upon selecting an option in the popup and clicking OK, it makes a request to the server, fetches some data and adds it to the main page.
When the swf is generated by the Flex Builder, everything works just fine. But when the same is generated using an ANT script, upon selecting a value from the popup, I get an error.
[ResultEvent messageId="8638F71F-BCB8-ACFD-E577-B6F97156374D" type="result" bubbles=false cancelable=true eventPhase=2]
This happens only when ANT is used for building the swf.
<mxmlc output="$swf_name" file="$mxml_name" allow-source-path-overlap="true" optimize="true">
I'm using the Cairngorm framework, and the swc is generated before hand.
<compc output="$swc_name">
Also there is a size difference between the final outputs.
The swf is 802 KB when generated from Flex Builder whereas its only 788 KB when generated using ANT. I haven't made any config changes in Flex Builder. It uses the default values(which I believe is optimized) for generating swf.
Am I doing anything wrong with ANT scripts? Do I need to use any different arguments so that I can remove the error which I get only when using the swf built by mxmlc?
Please provide your suggestions.
There could be differences between your configurations; have a look here -- this Adobe KB article might help you determine whether there are, and if so, what they might be so you can correct them:
http://kb2.adobe.com/cps/404/kb404341.html
I hesitate to mention this second part, because I haven't often toggled between the two compilers (I generally stick with one or the other), but I can say that I've noticed this issue before myself, and as I recall there was a brief mention, in Ely Greenfield's talk at MAX this past month, about a push with Flex 4 to achieve parity between Flex Builder's compilers and their SDK counterparts -- suggesting that such parity doesn't quite exist today. So while I don't have much in the way of details on that, it does seem there are some differences between the two.
Wish I could be more helpful on that -- maybe someone with a little more detail could chime in on it.

In Flex, what's the best way to remove a swf that was authored in Flash CS3?

So, I have an application where I'll be loading any number of swfs into a SWFLoader and removing them at runtime. The issue is - they are all timeline based movies authored in Flash CS3. I have very little control over what is in the movie other than the authors are not able to program any interactivity (i.e. no event listeners) but I want to make sure I am using the best technique to stop and trash these things so they don't hang around in memory too long. Here is the process I use right now to get rid of them:
Try stopping the content using MovieClip(content).stop();
Remove any listeners that I know about (ENTER_FRAME, etc...)
Set the source of the SWFLoader to null.
cross fingers, pray, make sacrifice (human if need be)
So that seems to work but is some better (or more comprehensive) method that you guys use to accomplish this same task? In all honesty - I'm not entirely sure these things aren't just kept in memory but I don't hear them so I don't know that they are there...
That's pretty much right. Loader (what SWFLoader uses under the hood), removes it's loaded clip from the stage with .unload(), but depending on what the clip has referenced the clip still runs and events still fire.
Flash Player 10 added .unloadAndStop(), but that is mostly just doing the same thing you are.
You could also try giving an explicit SecurityDomain (and probably ApplicationDomain so any contained classes are separate as well) in the optional LoaderContext parameter to Loader.load(), to try to prevent it adding event listeners outside (if you don't trust the clip not to), and avoid forming any references to anything from the clip so it can be garbage collected — but apparently it might still not unload in some cases.

Resources