14 April 2009
For a while we have been wondering why we get a Security Sandbox Violation when we run an effect over a container that has a map in it. Just to make sure we all know what we’re talking about, here’s the error that we currently get:
SecurityError: Error #2122: Security sandbox violation: BitmapData.draw: http://10.44.181.34:8080/tls-hs/HomeServices.swf/[[DYNAMIC]]/1 cannot access http://mt0.google.com/mt/v=ap.92&hl=en&x=253&y=167&zoom=8&s=Galile. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
at flash.display::BitmapData/draw()
at mx.effects.effectClasses::MaskEffectInstance/getVisibleBounds()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\effects\effectClasses\MaskEffectInstance.as:771]
at mx.effects.effectClasses::MaskEffectInstance/initMask()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\effects\effectClasses\MaskEffectInstance.as:650]
at mx.effects.effectClasses::MaskEffectInstance/startEffect()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\effects\effectClasses\MaskEffectInstance.as:463]
at mx.effects::Effect/play()[E:\dev\3.1.0\frameworks\projects\framework\src\mx\effects\Effect.as:930]
..etc...
I think we have finally found the answer here. And the answer is…
You can’t. So don’t try.
When you run an effect, it attempts to render the entire container and everything in it to a bitmap, which it then processes to produce the effect. But as Pamela Fox explains in the Google Groups post, they don’t really want to allow people to render parts of their maps to bitmaps which people can then mess about with.
I’ve had a moan about this on three points:
- I can’t find any documentation anywhere that explicitly says that you can’t do effects over a map. At least if you type in “Google maps flash effects” there’s nothing that I could see to tell me that effects aren’t supported.
- I think effects should be able to run over a map. After all, the whole point of Flex it provide a “Rich” application, and effects are a sizeable part of that.
- The error message we get relates to a Sandbox Violation. How are we supposed to figure out from that that drawing to a bitmap (and hence effects) is disabled?
In the meantime, it seems we have to remove the map from the display list whilst an effect is playing, and that’s the solution described in the Google Groups post.
Update – I had a reply from Pamela Fox on the Google Maps team and there’s a issue for this here. Please star this issue and add to the growing band of developers who want to do effects stuff….
6 March 2009
I needed to print an exam ready for someone to fill in. Looking at the demos for printing in the SDK documentation, they were a bit thin on the ground.
According to the documentation, printing is simple – you create a FlexPrintJob, create your display objects and add them to the job using addObject() and then call send(). What could be easier?
Well a lot of things actually.
The documentation doesn’t mention a bunch of pitfalls that you need to overcome before you can print properly. Here is a brief list of the ones I found…
- Images need to be downloaded before you start printing. Image loading is inherently asynchronous, so if you request the images at print time, there is no guarantee that they will be loaded by the time printing occurs. So you have to explicitly go through your document, request each image, and wait until they are all loaded before starting to create the display objects for printing.
- The sample code in the documentation always seems to lay out the display objects with specific x and y coordinates. But what happens if you want to use the standard layout components? When I tried that, nothing appeared. I simply tried to use VBox and HBox to position the individual parts of the page, and whatever I tried, the layout of the controls on the display objects didn’t work properly. Its seems that you have to add any display objects that you want to print to the actual display list otherwise they won’t be laid out properly, if at all. In other words you have to add your printed page to a parent that already exists on the display list. There might be a function somewhere that you can call to ensure that all your pages are laid out, but I couldn’t find it.
- In addition to point 2, you have to allow the LayoutManager a few frames to actually perform the layout, otherwise some containers seemed to be laid out properly, but others didn’t. In my test app, I create the controls and then the printing is done at the other end of a callLater().
My working test app is here. The printed layout is pretty much the same as the displayed layout, and it only works because I have solved the particular problems described above.
27 February 2009
Right now I’m writing a Flex app that manages and runs online exams. Currently, the part of the app that shows the exam ready for the candidate to enter answers is part of the same application that allows a user to manage the details of the exams etc.
This is actually what the specification required. It might be the case that our candidates take the exam by ticking boxes on a piece of paper and then an admin enters the results later. But I think a candidate should be able to enter sit in front of a pc running the app and be able to take the exam online. Whilst taking the exam, the candidate should be prevented from accessing any other part of the app.
So I started thinking about maximising the exam. Sure enough, Flash allows us to show an app full screen. Full details of how to do this appear in the livedocs here.
But about half way down there’s a paragraph that’s a real killer…
All keyboard-related ActionScript, such as keyboard events and text entry in TextField instances, is disabled in full-screen mode. The exception is the keyboard shortcuts that close full-screen mode.
In other words, you can’t type into TextInput fields when your app is full screen. Note that this only applies to apps that run in Flash Player – if you’re writing for AIR, then StageDisplayState.FULL_SCREEN_INTERACTIVE is available and everything works as normal.
So I had to settle for making a particular container full screen within the application stage, i.e the browser. It turns out that this isn’t too difficult, as all you need to do is remove the display object that you want to make full screen from its parent and add it as a child of the System Manager.
That worked fine for me, but the test app I did removed a container from within a popup TitleWindow. I found that although the container was now a child of the the top-level System Manager, the popup (which used to be its parent) still showed over the top. So I also had to hide all popups whilst my container is full screen.
My test app is here. To quote one of my Flex Heroes, Alex Harui, “the usual caveats apply”…
18 February 2009
..and here is a test app that shows it working.
I originally had a go with the SDK OLAP classes. One of my previous posts here shows a test app that I produced. This app shows just a grid with the cube output.
But we wanted to put the data in a chart. I had a good look at the source code for OLAPCube etc and I just couldn’t understand any of it. It seems way too complicated – I guess it has a whole load of functionality that I don’t understand and probably will never need.
So I had a go at creating my own simplistic OLAP Cube. It quite happily allows me to add dimensions made up of one data column. I know that the SDK classes allow you to create a hierarchy of columns, i.e. you build up a dimension out of more than one column. Whilst we don’t need anything like that at the moment, I’m pretty sure I could add that functionality to my classes if I need to.
So my Cube classes seem to work, they are simple to understand, and I can output the data to a chart (although in the test app the charting a bit odd – I need to introduce drag and drop in there somewhere…)
Finally, my Cube classes don’t come with a price tag like the advanced classes in the SDK….
18 February 2009
If you have ever tried to create multiple columns within a Form, I guess you probably gave up. So did I. Until I realised that a Form is a pretty simple little class that just arranges the FormItems within it. I think I approached the problem thinking that <mx:Form> was like a HTML form, i.e. it had some functionality that managed the form items. But no, it’s just a container.
The next problem was that we had some forms that had only one column and some that had more. If you have a specific style for Form in your stylesheet, the multi-column forms will look wrong, for example each column may have a border around it.
The easy solution is to derive a class from HBox, call it MultiColumnForm, and derive a class from Form, call it FormColumn. You can then create multi-column forms by embedding FormColumn objects inside a MultiColumnForm. You can style MultiColumnForm and FormColum explicitly in your stylesheet without worrying about styles clashing with Form.
Here is my little test app.
18 February 2009
Alex Harui has a post here about having a dummy line at the bottom of a DataGrid that the user could tab to or click on to add a new line. Alex’s version uses arrays of objects. However, we use a lot of XML in our projects, and whilst we could actually make it work with an XMLList, I set about trying to do it properly with an XMLListAdapter, which is the XML equivalent of the ArrayCollection. I think I managed it, but it was difficult because I ran in to a couple of issues with DataGrid and the XMLListAdapter itself. I couldn’t get the grid to work properly without these changes.
My test app is here. As usual you can right-click and select “view source”.
15 January 2009
Back in the days when I was doing Windows 3.0 with Microsoft C 6.0, you could add a try/catch block around the message loop and your app would happily show you when any runtime error occurred.
Unfortunately the standard Flash Player and AIR runtime just ignore any such errors – the user won’t get an error message and will most likely just see very strange and erroneous behaviour, and there is absolutely nothing useful he or she can tell the developers.
It seems that this is a big issue with developers as it really restricts our ability to track down bugs in live systems. There’s a bug report here - Ability to intercept system error dialogs - for Flash Player. It’s been hanging around since June 2007, and nothing appears to have been done. Please vote for this one, add a comment, and add your voice to the ever growing band of developers who need a global error handler of some sort.
13 January 2009
I just love the look and feel of this website, and as you might expect, it uses Flash Player. The app loads in no time, the response is good, and the animations run smoothly.
And it tells me that I’m getting a decent download speed from my ISP…