tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/177-mediating-a-swfs-document-class-causes-an-errorRobotlegs: Discussion 2018-10-18T16:35:17Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T13:15:58Z2010-09-29T13:15:58ZMediating a swf's document class causes an Error<div><p>Interesting. How are you mediating the document class directly without compiling it into your shell swf?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T13:19:44Z2010-09-29T13:19:44ZMediating a swf's document class causes an Error<div><p>Hi Pedr,</p>
<p>This is an interesting one,</p>
<p>usually the error you're describing happens when you declare a stage item (like a MC) with a name on the stage, where you don't have "automatically declare stage instances" checked in your publish settings.</p>
<p>Workarounds include making your document class dynamic, or adding the item using code in the document class. Or of course you can check the "automatically declare stage instances" option.</p>
<p>But.. it sounds like this exact swf was fine until you put it directly into the mediator map?</p>
<p>If you can confirm that this is the case, we can look into it a bit more.</p>
<p>Personally I don't mediate the swfs I load directly. I wrap them in a bridging view class (to which they are added) and I mediate that. I think that's an easier workflow to understand - keeps the responsibilities more separate, and also makes your app more flexible as it's not coupled to the loading of a specific swf.</p>
<p>The other option is to simply relay the sharedEventDispatcher events to and from the main robotlegs eventDispatcher. I'm a fan of this approach as well, as it creates a class which very neatly describes the event flow between the two parties.</p>
<p>I hope this is helpful,</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T13:46:01Z2010-09-29T13:46:04ZMediating a swf's document class causes an Error<div><p>@Sean</p>
<p>Sorry - not sure what you mean. I'm Mediating it as I would any component - mediatorMap.mapView( SomeDocument, SomeDocumentMediator). Are you suggesting the problem is something to do with different application domains?</p>
<p>@Stray</p>
<p>Thanks.</p>
<pre><code> If you can confirm that this is the case, we can look into it a bit more.</code></pre>
<p>Yep. It's not any of the things I would normally expect to throw throw this error. It is definitely getting thrown as a result of the Mediation directly or indirectly, but I'm not getting anything helpful in the stack.</p>
<p>As far as Mediating it directly, it's a small piece of functionality I have had to snap off from the main app into a fla that can be edited and replicated by people who know almost nothing about code. I want to treat it like it is just another component and Mediate it directly without caring that it has been loaded as a swf.</p>
<p>I've put together a simple example (attached).<br />
</p></div>Pedrtag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T13:53:31Z2010-09-29T13:53:32ZMediating a swf's document class causes an Error<div><p>@Stray</p>
<p>Thanks. Making the document class dynamic stops the error being thrown, but it would still be interesting to know why this is happening.</p></div>Pedrtag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T14:02:44Z2010-09-29T14:02:44ZMediating a swf's document class causes an Error<div><p>Hi Pedr,</p>
<p>the reason it happens is because of what Shaun picked up on - you are importing the document class into your main App to map against.</p>
<p>However, when you have that 'auto declare stage instances' checked, flash edits the document class at export and effectively makes it dynamic.</p>
<p>Because the non-dynamic document class is the first one the app loads (before the swf loads) you're loading the non-dynamic one, and your swf is instantiating using this version and not the dynamic version that is compiled in the swf.</p>
<p>[I haven't done a joa and looked in the byte code to discover this, it's just from trial and error]</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T14:05:22Z2010-09-29T14:05:22ZMediating a swf's document class causes an Error<div><p>Maybe<br />
public static const URL:String = "assets/runtime/swf/someSWF.swf";<br />
instead of<br />
public static const URL:String = "runtime/swf/someSWF.swf";</p>
<p>would at least eliminate the ReferenceError: Error <a href="/discussions/problems/1056" title="Discussion #1056">#1056</a><br />
Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T14:16:43Z2010-09-29T14:16:43ZMediating a swf's document class causes an Error<div><blockquote><p>Maybe
public static const URL:String = "assets/runtime/swf/someSWF.swf";
instead of
public static const URL:String = "runtime/swf/someSWF.swf";</p>
<p>would at least eliminate the ReferenceError: Error <a href="/discussions/problems/1056" title="Discussion #1056">#1056</a></p></blockquote>
<p>The reference error is generated inside the swf, so the path to the swf shouldn't affect it.</p>
<p>Did you compile and find this eliminated? Would throw our dynamic / application theories out ... so it would be good to know if this is the case.</p>
<p>Stray</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T14:29:21Z2010-09-29T14:29:24ZMediating a swf's document class causes an Error<div><p>@Stray</p>
<p>You and Sean were right. I decompiled the swf and Flash adds:</p>
<p>public var movieClip_1:MovieClip;</p>
<p>to the document class. Obviously my original document class was used and when the sprite tried to assign movieClip_1 the variable it is expecting isn't there , causing the error. I'm still slightly confused by how the movieClip_1 actually gets created and assigned, but I guess that's another far more complicated story.</p>
<p>Thanks for your help.</p></div>Pedrtag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T14:34:01Z2010-09-29T14:34:01ZMediating a swf's document class causes an Error<div><p>It's just part of what the 'automatically declare stage instances' does. It's not even just dynamic in that case - it's actually declaring the variable in the document class. I had thought it made it dynamic as well (if you can see that in your decompiled class I'd be interested to know).</p>
<p>Great stuff - glad we got to the (typically adobe-style obscure) cause of it!</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T14:48:27Z2010-09-29T14:48:28ZMediating a swf's document class causes an Error<div><p>No dynamic to be found:</p>
<p>package app.view.ui.flash<br />
{</p>
<pre><code>import flash.display.*;
public class SomeDocumentClass extends Sprite {
public var movieClip_1:MovieClip;
public function SomeDocumentClass() {
return;
}
}</code></pre>
<p>}</p></div>Pedrtag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T14:55:07Z2010-09-29T14:55:07ZMediating a swf's document class causes an Error<div><p>Great - thanks - good to know what it's doing!</p>
<p>Did you know that all the frame code is represented as functions called function1 function23 (if it's on frame 23) and so on?</p>
<p>Amazing what the compiler for FLAs gets up to.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T15:02:43Z2010-09-29T15:02:43ZMediating a swf's document class causes an Error<div><p>By the way, if you want to avoid compiling that class into both SWFs, you could map against the class name and inject an interface:</p>
<pre>
mediatorMap.mapView("package.to.your::ViewClass", SomeMediator, ISomeView);
</pre>
<p>And your mediator would manipulate the view through that interface:</p>
<pre>
[Inject]
public var view:ISomeView;
</pre>
<p>Might also solve the original issue.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T15:05:18Z2010-09-29T15:05:18ZMediating a swf's document class causes an Error<div><p>@Stray: I think it's amazing that Adobe managed to get AS3 to work on the timeline at all!</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T15:07:11Z2010-09-29T15:07:11ZMediating a swf's document class causes an Error<div><p>Yep. The good old undocumented addFrameScript(). Definitely handy to know<br />
about.</p>
<p>On 29 September 2010 15:57, Stray <<br />
<a href="mailto:tender+ddbfdcecef58f7a394e90acaaaba02fc115252a6b@tenderapp.com">tender+ddbfdcecef58f7a394e90acaaaba02fc115252a6b@tenderapp.com</a><<a href="mailto:tender%2Bddbfdcecef58f7a394e90acaaaba02fc115252a6b@tenderapp.com">tender%2Bddbfdcecef58f7a394e90acaaaba02fc115252a6b@tenderapp.com</a>><br />
</p>
<blockquote><p>wrote:</p></blockquote></div>pedr brownetag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-29T15:25:02Z2010-09-29T15:25:02ZMediating a swf's document class causes an Error<div><p>It's a beautiful thing. We now set up most FLA code in an xml doc and apply it all that way. Easier than scrubbing through 8000 frames to find out what the hell the designer accidentally copied / deleted ...</p>
<p>And Shaun - you're right. The whole FLA / swf thing is quite miraculous - the inconsistencies are fairly exceptional under the circumstances!</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-30T07:34:12Z2010-09-30T07:34:12ZMediating a swf's document class causes an Error<div><p>I tried to load the swf like so:</p>
<p><a href="http://gist.github.com/604180">http://gist.github.com/604180</a></p>
<p>This works. I don’t know if that’s what you wanted to achieve or if<br />
you found a better solution already.<br />
I'd be interested to hear how you guys solved the issue or if you tried what Shaun<br />
suggested.</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-30T07:47:50Z2010-09-30T07:47:50ZMediating a swf's document class causes an Error<div><p>Hi Ondina,</p>
<p>the problem was that (as we suspected) Flash actually amends the document class to give it the children as stage properties when it exports the swf, because 'automatically declare stage instances' is checked.</p>
<p>The Class being imported into the loading app was the unamended version of the document class. Making the document class dynamic did the trick (as it is the first one loaded it is then used in the swf once it is loaded too, but doesn't have the amendments that Flash made on publish).</p>
<p>Pathing wasn't (as far as we can see) relevant - it was the additional properties the flash compiler adds that were the missing ingredient.</p></div>Straytag:robotlegs.tenderapp.com,2009-10-18:Comment/31521152010-09-30T08:09:40Z2010-09-30T08:09:40ZMediating a swf's document class causes an Error<div><p>Hi Stray,</p>
<p>true, the pathing wasn’t the problem. My compiler complained though the first time I tried Pedr’s example and I didn’t see that it came from the loaded swf. Sorry about that.</p>
<p>I tried Pedr’s original example with a dynamic class and it didn’t work. Maybe I was doing something wrong.</p>
<p>In my example I didn’t have to make the class dynamic. The swf is added to the stage on loader complete event. That’s all.</p>
<p>Ondina</p></div>Ondina D.F.