Jeff dePascale Blogging on and developing web and mobile technologies

20Mar/092

Cross domain policy files, secure servers, and loads from virtual directories

Two unique issues regarding cross domain policies.

First, in regards to connecting via https://, if you are connecting from a non secure environment, the domain in question must have '-secure="false"' appended to it, for example:

<?xml version="1.0" ?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
- <cross-domain-policy>
<allow-access-from domain="*.yourinsecuredomain.com" secure="false" />
</cross-domain-policy>

Second, virtual directories...typically your cross domain file is loaded into the root of the server. You'll still need to do that. However, you will need a duplicate cross domain file at the virtual directory level as well. Load the domain root file via Security.loadPolicyFile("http"//www.yourdomain.com/crossdomain.xml"). The second policy file at virtual directory root level does not need to get loaded the same way, however it is checked for automatically when loading the actual content.

13Mar/090

Tabbing out of components – focusManager.deactivate()

While building the new tab manager for Fosfr I came across yet another tab ordering glitch - those pesky focus managers. Designed to make focus handling easier, the way they are implemented within components can be a bit of a hassle when defining your own order. If your tabIndex for a component is, say, 5, and tabindex 6 is an object that does not have it's own focusManager (say a textField or MovieClip), the built in focus manager will break out of your indexing and force the tab order back to the root tab item for the WHOLE flash player. With fosfr, that means something in your main or shell swf, typically near the top left if you didnt reorder all your tabs by hand. To fix this (and only do this if you are controlling tabbing yourself), set all of your indexes, and for your components, set component.focusManager.deactivate(). This will allow the custom tabbing yo have set to work.

With Fosfr .8, this will all be a thing of the past as it is all built in now by default. Tab items will map themselves, and, if the order is incorrect, you can override the order yourself via a new method of FosfrSubSWF, setTabOrder(array:Array);

13Mar/090

Referencing component classes – fl.*

I'm not sure why Adobe chose to leave the entire fl.* package out of the standard set of actionscript 3 classes in CS3 - I'm sure they have their reasons. The problem however is that sometimes you either a:) have to reference an instance of something from a class associated with another loaded SWF, meaning that you dont have the component in the library of the SWF being published, or b:) would like to use a class from the fl.* package without an associated component. The FocusManager class is a good example. Frequently I see the solution to this problem listed as adding the component shim to your library, which contains all the classes. But that's problematic for two reasons. One, what if you're developing pure AS and dont HAVE a library to just drop that component into? Sure, you could embed it through your code, but again, wouldnt an import make more sense? And two, why should you need a library item to reference a class? It's an option, yes, but you shouldn't be forced into doing it.

Luckily, there's a simple solution to this. Turns out the entire fl.* package is located on your hard drive already with Flash CS3. You just need to map it. So, get your copy/paste fingers ready, and add this to your as3 classes list under actionscript preferences:

C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Component Source\ActionScript 3.0\User Interface

And for you mac people out there, something along the lines of this:

Macintosh HD:Applications:Adobe Flash CS3:Configuration:Component Source:ActionScript 3.0:User Interface

Your path may be different (I think vista's path structure is different for example), but from the 'Adobe Flash CS3' folder onward it should be identical.

I haven't jumped into CS4 yet, so perhaps they addressed this by default by now...anyone check yet?

11Mar/090

Custom Events in loaded SWF files

Custom events that override the clone method of Event implemented in a loaded SWF file that has listeners in the parent or above will fail with a 1034 coercion error, even though the error seemingly says that the type it is coercing to is the same class type. After much searching I found the answer i needed - something i've come across before when building fosfr. I'm not entirely clear on why this only affects custom events with clone overriden and not others, but the solution is to import the custom event in the root document class and reference an instance of it, thereby forcing the root displayObject to include the event class in its compile. From that point forward it is accessible throughout the SWF hierarchy. You don't need to create an actual instance of the event, just reference it by name. Example:

package {
import my.custom.CustomEvent;

public class Main extends MovieClip {

CustomEvent;

pubic function Main(){
}
}
}

This is definitely required in Fosfr projects given the aformentioned use case. Note that it doesnt appear to cause issues when not listening down in the display list, like this case specifies. Listening up is fine, dispatching up is not.

Hopefully that'll save some of you the hour it took me to find that answer!

Tagged as: , No Comments