Posted by cdprod in SWF Studio V3 on Mar 28 2008, 02:26 am

I am trying to load a flash 8 swf from flex. It works fine running in flex builder or under browser. I read the post re as3 and as2 which I though was encouraging.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1366" height="768" 
      paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0">
   <mx:Canvas>
      <mx:SWFLoader source="ClockDigital.swf"/>
   </mx:Canvas>   
</mx:Application>


Any suggestions would be welcome, we have a significant amount of as2 code to upgrade (eventually).

thanks


Posted by mbd in SWF Studio V3 on Mar 28 2008, 03:51 pm

This actually has nothing to do with AS2 or Flash 8. There is an issue using SWFLoader in a SWF Studio application.

The problem has to do with relative vs. absolute paths, the SWFLoader component, and where the core SWF is loaded.

If you take a look at the code for SWFLoader you'll find this in the loadContent function:

QUOTE:
// make relative paths relative to the SWF loading it, not the top-level SWF

The component will make a relative path absolute based on the URL of the SWF that loaded it. In this case it's the core SWF that loads the main SWF. The core SWF originates in the temp folder. So, SWFLoader should always try to load relative paths from the temp folder, however, the Flash Player is not returning a proper URL.

There are two solutions:

1. Create your own implementation of SWFLoader that doesn't mess with the URL. That could involve creating your own component/class or simply using Loader instead.

2. Specify a full path. Because you probably won't know the actual path to hardcode, you can use ssGlobals.ssStartDir (for paths relative to the EXE launch folder) or ssGlobals.ssTempDir (for paths relative to the temp folder - auto extract folder).

Example:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="1366" height="768" 
      paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0">
   <mx:Canvas>
      <mx:SWFLoader source="{ssStartDir}\ClockDigital.swf"/>
   </mx:Canvas>
   <mx:Script>
      <![CDATA[
         private var ssStartDir:String = (ssCore.isEXE)?(ssGlobals.ssStartDir+'\\'):('');
      ]]>
   </mx:Script>
</mx:Application>

It might look a little daunting, but there's a reason why it's not as simple as placing {ssGlobals.ssStartDir}\ in the path. That would probably work if you're using the Flex 3 SDK. According to Adobe there's a known issue with specifying a value like:


You'll get a compiler error if you're using the Flex 2 SDK. The workaround is to create a reference and use that, which is the reason for the ssStartDir private variable. It also lets you specify an empty string in the case where your project is used outside of SWF Studio.

If you want to load a file directly from the layout without extracting it first, you should use ssURLLoader and the Loader object and option 1 above.