-
[CS3] .onLoad Problem
Hey everyone,
So I've been working on a Flash-based web portfolio for my sound design work, and I'm creating a gallery of images/sound clips which load dynamically (that way I don't need to recompress the swf file every time I add/remove a production). I'm having trouble with checking to see if files exist; for example, I want to check if a sound file exists, and if it does, set the alpha property of a symbol to 100%, and if it doesn't, set the alpha property of that symbol to 25%.
The code I'm using works fine when I test the file locally, but as soon as I upload the file and test it, the movie responds as if a file exists even when it doesn't, and I can't figure out why.
Here's the code in question:
fileExists = new LoadVars ();
fileExists._parent=this;
fileExists.onLoad = function (success) {
if(success) {
mySound.loadSound(this_sound,true);
mySound.stop();
mySound.setVolume(25);
_root.play_btn._alpha=100;
_root.stop_btn._alpha=100;
_root.volume_bar._alpha=100;
} else {
delete mySound;
mySound = new Sound();
_root.play_btn._alpha=25;
_root.stop_btn._alpha=25;
_root.volume_bar._alpha=25;
}
}
fileExists.load("somesound.mp3");
Why would this code behave correctly (i.e. change the alpha settings as expected) locally, but not online?
Thanks for your help.
-
Did you empty your browser cache when testing online ?
-
As far as i can see in the flash help LoadVars should not be used to download binary files like mp3s...
This is from the flash cs3 help :
Note: If a file being loaded contains non-ASCII characters (as found in many non-English languages), it is recommended that you save the file with UTF-8 or UTF-16 encoding as opposed to a non-Unicode format like ASCII.
-
I understand you are using the LoadVar to test if a file exists...but I doubt the response will be accurate when its not designed to do this...
-
-
did you try with the full url instead of 'somesound.mp3'
fileExists.load("somesound.mp3");
-
OK... i tried your code... i should have done that first...
Im using Flash CS3, exporting swf for flash player 9
your example works online and offline. I replaced your somesound.mp3 by the relative path of a jpeg i already had in a folder online and offline...
Everything works for me... maybe its more a security related bug...
my code :
Code:
fileExists = new LoadVars ();
fileExists._parent=this;
fileExists.onLoad = function (success) {
if(success) {
testbox.text='Sound loaded!';
} else {
testbox.text='Sound not loaded!';
}
}
fileExists.load("gallery/thumb_01.jpg");
-
I have to tell... in my previous post everything works: its not displayed 'Sound loaded' when the file does not exists, but instead, the code in onLoad is never called so I guess you can manage that by setting your opacity & volume to 25 before attempting to check if the file exists so when it does not its already in the right state (ie grayed and disabled)
-
graben,
Thanks for your messages; seems like you spent a lot of time on this today. It may be a security issue (it's not a browser caching issue, though it took me a little while before I tried that!), but I wouldn't even know how to check that.
I think, though, what you say in your last post has some possibilities of bearing fruit--I'll try starting with the 25% alpha settings as the "default" and only change them when .onLoad gets called.
Though I still have to wonder why the code executes as you'd expect locally. Weird.
Thanks for your help.
orph
-
Check the new thread I just created:
http://board.flashkit.com/board/showthread.php?t=787053
my code works well in IE 6 and 7. But on Firefox 3 only after you reload the page !
Flash is so weird sometimes...