0

Background

I would like to write an AI for a certain Flash game, and as part of that I want to train an image recognizer with elements of the game. In order to do that, first I want to generate many samples with various configurations that can be used as training data.

In the generating process I have to use the game itself which I have in SWF format. My conception is to create my own Flash app that accesses the game SWF and uses its classes to generate the images (I have reverse engineered the game SWF with a tool, hence I know which classes I need).

Question

I created an mxml file with the following content:

<?xml version="1.0"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Script><![CDATA[
        public function onLoad():void {
            var clazz:Class = loader.loaderInfo.applicationDomain.getDefinition("com.game.Foo") as Class;
            // here I will use clazz
        }
        ]]></fx:Script>
    <mx:SWFLoader id="loader" source="GAME.swf" complete="onLoad()" />
</s:WindowedApplication>

The problem is that when GAME.swf is loaded, its main MovieClip is started automatically, its constructor is invoked even before my onLoad() event handler. Since the environment is different from what the game expects, the constructor fails with an exception and onLoad() is never called.

So the ultimate question is how to achieve that GAME.swf not be started when it is loaded, but I am also looking for other suggestion or solution that is different from that described above.

5
  • very likely the loaded game expects a valid stage in the constructor. It can be considered a mistake by the author or a good protection against whatever you intended to do with what wasn't yours.
    – BotMaster
    Feb 3, 2016 at 3:31
  • @BotMaster Thank you for your remark. Although I am aware, what I want to accomplish may be considered greyish, I am doing it as private research and there is no way of monetizing it. If you or someone else has the solution or a suggestion, I appreciate it. Feb 3, 2016 at 8:57
  • 1
    Try not to add swf to stage - i.e. don't add SWFLoader to mxmlc but load swf in script. If game has a check for stage (listen for ADDED_TO_STAGE event it will no run)
    – fsbmain
    Feb 3, 2016 at 10:53
  • 1
    There's no solutions, loading a swf means that an instance of it is created, if an error occurs in constructor then that's the end of it. Like I said this is the author privilege to require a valid stage in constructor which ensure that this swf can only run as the primary swf and not be loaded by other swfs.
    – BotMaster
    Feb 3, 2016 at 11:57
  • Can you elaborate on "Since the environment is different from what the game expects, the constructor fails with an exception"? What exception is thrown? What does the game expect? Certainly you cannot prevent the constructor from running. But there may be another solution to make the "environment" acceptable, yet under your control. We can only guess with the information you provided. Feb 3, 2016 at 22:47

1 Answer 1

0

The solution was to modify the byte code in SWF files using FFDec, and remove the failing part from the main MovieClip's constructor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.