loadbytes throws TypeError: Error #1007:

Hi all !

I have been trying out this little snippet of code below -

import flash.display.Loader;
import flash.display.Sprite;
import flash.system.ApplicationDomain;
import flash.system.LoaderContext;

[SWF (width = 550, height = 400)] //the dimensions should be same as the loaded swf's
public class Main extends Sprite
    [Embed (source = "xyz.swf", mimeType = "application/octet-stream")]
    // source = path to the swf you want to protect
    private var content:Class;
	private var context : LoaderContext = new LoaderContext(false, new ApplicationDomain());
    public function Main():void
        var loader:Loader = new Loader();
        loader.loadBytes(new content(), context);


and it results always in the following error.

TypeError: Error #1007: Instantiation attempted on a non-constructor.
at Main$iinit()[D:\shim\Main.as:20]

which happens to be the line

loader.loadBytes(new content(), context);

I’ld be grateful for any help.

Thanks all !

The error seems to occur because

private var content:Class;

remains uninitialized. All examples of code that I have encountered have used the Class variable like that. Some of them choose it to use a const instead of a var. I don’t think that matters. What matters is that it probably has a null value.

P.S. I am using Flash CS3 for coding and testing.

Kindly help.

Thanks !

I guess the Embed is getting messed up. I can’t remember what support CS3 has for it (though I would expect an error if it wasn’t supported)… Or maybe the comment is possibly getting in the way? Are you sure the source path is right?

Hi Senocular !!

Thanks for the response. The source path is correct since everything is in the same folder.

I’ll remove the source path and try out as well.

Thanks for that. But I have begun to suspect that this would maybe need a flex compiler.

I’ll revert. Thanks a ton for the reply.


It does not have to do with the comments. I removed both comments. The result was the same.


yeah those annotations ([SWF…] and [Embed…]) are generally used outside of the Flash authoring tool and used with the flex/standalone compiler. If I remember correctly, at some point Flash authoring supported some of those but I’m not sure when and to what extent. [SWF…] I’d imagine would get ignored in favor of the publish settings in Flash, but [Embed…] might work. Then again, maybe not, and I’m not remembering things correctly. You might be able to go through the docs to find out, but again, it might have happened after CS3, so if you find support exists, see if you can link that to a version too.

Hi Senocular,

Thanks for the reply and suggestions.

So I went and downloaded your very own tutorial on flex command line here and did the needful. (The make file was extremely helpful) I compiled the code using the command line flex compiler mxmlc.exe but to my dismay, the errors remain. However I am getting 3 different errors, the first being

VerifyError: Error #1014: Class mx.core::ByteArrayAsset could not be found.

I had thought that the [embed ( … )] tag would have provided the data !??

The other two are i think a consequence if the 1st and are

  ReferenceError: Error #1065: Variable Main_content is not defined.
  ReferenceError: Error #1065: Variable Main is not defined.

From the example and many others that I looked for on the net, it would seem that

new content() in the line -------> loader.loadBytes(new content(), context);

would be of the form BytesArray.

Here is another almost identical example.

Kindly look into and suggest.
Thanks loads !