Preloading troubles and the structure of a Swf [Solved]

4 posts

Flag Post

E: Solved, see 2 posts down.

Long story short, I have been trying to make a preloader by using HaXe to create the ‘substance’ of my code, and SamHaXe to embed the assets on frame 2 (as HaXe does not consider frames a thing, and Adobe has yet to realise that frame-based one-file async loading has not been a clever thing since AS1).

Below is a diagram of the structure of my swfs, along with explanation.

In every case, it throws ArgumentError: Error #2068: Invalid sound. when I try to play an instance of resources.Music, and my sound has a totalBytes value of 0, indicating that it is an ‘empty sound’ (has no sound data associated with it. Just a husk). This makes sense in (1), but in (2), the intent is to get the sound data in there so that that does not happen.

I am waiting until the swf is fully loaded before trying to play the sounds.

Link to image [LOOK AT THIS!]

SamHaXe reference

1: This is the swf I initially compiled. It contains mostly bootup classes for getting everything started, and a small preloader

2: This is a ‘Class stub’ for resources.Music. The purpose of this is to allow me to compile with references to the class. If I did not include a ‘stub’ like this, I would be unable to compile because resources.Music does not yet exist, yet I reference it. Code for the stub is at the end

3: This is the swf compiled using the original swf as frame 0, and embedding an mp3 file as a Sound object, with class ‘resources.Music’ in frame 1. My preloader is functional for this one. The filesize is correct, and it the preloader loads and displays before the rest is loaded. I cannot, however, succesfully use resources.Music in any way.

4: resources.Music appears here under ‘Frame 0’, just as in the original project

5: When I compile with genclass=“symbolAndClass”, resources.Music appears again under ‘Frame 1’. This has SamHaXe generate a class itself. It is not intended for use with a manually-created stub, but I cannot find any way to make the project compile the first time without a stub. Case B is the recommended way, where I create the class and SamHaXe creates the symbol.

6: The resources.Music symbol is created by SamHaXe in either case. This holds the actual data of the mp3 file.

I believe the problem is that the resources.Music symbol exists ‘in frame 1’ while the resources.Music class exists ‘in frame 0’. When I reference resources.Music, it looks at the class from frame 0, which is just an ‘empty sound’, and throws an error at me. It never gets pointed to the data in frame 1, because, in case A, it sees the “wrong” class, not linked to any symbol, and in case B, the symbol does not have any class linked to it.

I could be wrong. I am by no means an expert on the structure of a swf. But this is what seems most likely to me. If anyone has anything to contribute to my efforts, it would be much appreciated.

Music class stub:

package resources;
class Music extends{ public function new() { super(); } }

SamHaXe resources.xml file:
note that I’ve tried with the genclass property as both “symbolAndClass” and “symbolOnly”

<?xml version="1.0" encoding="utf-8"?>

<shx:resources version="10" compress="false" package="resources" w="800" h="600" fps="30"

      <swf:library import="proj.swf" symbols="true" />

      <snd:sound import="sound.mp3" class="Music"/ genclass="symbolAndClass">

Flag Post

try putting in extra delay and loading a smaller sound and see what happens.

Flag Post

Tried using a small (60kb, like 1 second) sound file. put a 10 second delay between loading complete and creating the sound, and a 10 second delay between creating the sound and playing the sound. No changes.


s = new Music()...

I would swear I did that before…

Still, weird that that should be the case. Any explanation?

Flag Post

the constructor? Maybe it s was null before. But then again, it should say null reference. But I have no idea how Music works.