1

I have a working Flash movie, using a couple of AS3 scripts. The main stage has some animation going on. My player.as plays some mp3 clips when I click a button. The problem is, the stage animation stops as soon as the sound starts ie. Sound.play() starts, then animation starts again when the sound ends.

The animation is based on

this.addEventListener(Event.ENTER_FRAME,loop3D);

so I gather something happens to ENTER_FRAME due to Sound.play(). What is weird is everything works perfectly on the Flash Test movie (ctrl+Enter). The animation does NOT stop during sound. What to do to make sure the animation goes on always?

distill
  • 61
  • 1
  • 3
  • 2
    Is there any more code we can look at? –  Feb 13 '11 at 02:03
  • I don't know what is relevant to paste here.. What I do notice is that if I simply comment out 1: mysound.play(pos) or 2: sndarray[current].play(), which are what happens if buttons 1 or 2 are pressed, that completely removes the problem. Then I can still enjoy the animation on a live website after pressing the buttons. But of course then no sound at all. So I've pinned it down to .play(). The animation is a .computeSpectrum thing, 3D reacting to sound. Note that it does work perfectly when offline, on Test movie. – distill Feb 13 '11 at 09:24
  • I could now debug it further: If I play a sound on the same .as where the .computeSpectrum is, animation works even online. So it was not a problem with animation stopping, it is a problem where the sound ByteArray from another .as doesn't pass on properly (strange that there is a difference whether doing Test movie or online). So, this `bytes = new ByteArray();` is where it probably goes wrong. That works if the `Sound.play();` is on same script, but how to get that working if the sound is coming from another .as? – distill Feb 13 '11 at 09:47
  • There might be some sort of security problem where the other .as is not accepted by `SoundMixer.computeSpectrum(bytes, true, 4);` so the animation just when sound is played by another .as file. One solution would be to combine all my .as to the main class, but that's a huge job for me and sounds very stupid. I just want to computeSpectrum in one .swf, all sound is produced in one and same .swf! How to pass (or mix) audio bytes between classes? – distill Feb 13 '11 at 11:18
  • Found out that it also stops in Firefox if I open a YouTube video in another tab at the same time. This I pinpointed as a bug. However, I would really like to get this working even with the Firefox YouTube problem. Surely somebody has done a spectrum analyzer with a separate .as class playing the sound? – distill Feb 13 '11 at 15:42

1 Answers1

1

There is no inherent problem with playing sound and animation at the same time, nor is there one with combining a (however large) number of class files - you have another problem. There must be an error causing the Flash player to suspend execution of ActionScripts, and it is most probably one of these:

  1. A security sandbox violation.

  2. An IO error or a problem related to playing stuff that has not yet completed loading.

  3. A problem related to loading classes from a separate SWF.

  4. Some other problem causing a null pointer exception.

To debug this, first check your flashlog.txt. If you don't have one, set up the Flash content debugger plugin. See what error codes are thrown, go on from there.

Community
  • 1
  • 1
weltraumpirat
  • 22,544
  • 5
  • 40
  • 54
  • Thank you very much, that helped me a lot. I found out two things, it was indeed a security sandbox problem. Annoyingly, the problem actually wasn't there when accessing www.mysite.com. I had been debugging on mysite.com, without the www prefix. The security problem exists only if www is left out. I tried all sorts of things but could not find the answer for this new problem. How to allow full sandbox permissions for the same website without www prefix? – distill Feb 14 '11 at 18:01
  • Allow access from *.mysite.com – weltraumpirat Feb 14 '11 at 20:21
  • Yes, that's what I'd like to do. How? At least `Security.allowDomain("*");` doesn't work. – distill Feb 14 '11 at 22:10
  • Set up a crossdomain.xml. Also, the HTML you embed the swf in might need allowScriptAccess="always". Check this: http://kb2.adobe.com/cps/403/kb403183.html – weltraumpirat Feb 14 '11 at 22:19
  • Thank you again. I'd be delighted to also get an example for the crossdomain.xml, but of course I can try to figure it out myself too. I found several examples but they radically differed from each other, I do not know which one is proper for this simple purpose. Also I don't know where to put the file and what to add to the document class though I tried a couple of things. – distill Feb 15 '11 at 11:41
  • http://stackoverflow.com/questions/213251/can-someone-post-a-well-formed-crossdomain-xml-sample – weltraumpirat Feb 15 '11 at 11:58