|
-
[RESOLVED] Creating filepath out of strings
I know I'm close, but can't find what I'm doing wrong.
If I remove the variables and just type in the path name, the file does play. So there's no other error in this piece of code.
I just can't seem to figure out how to create that filename from variables.
If anyone could help me out I'd be very grateful.
Thx in advance!
EDIT: I should point out more clearly its about the line = public var soundRequest:URLRequest = new URLRequest("sounds/" + Champ + soundType + ".mp3");
I get a 2044 unhandled ioerrorevent error and a 2032 stream error.
Actionscript Code:
package { import flash.display.*; import flash.events.*; import flash.net.*; import flash.media.*; public class button extends MovieClip { public var btn1:MovieClip; public var btn2:MovieClip; public var Champ:String = new String(); public var soundType:String = new String(); public var soundRequest:URLRequest = new URLRequest("sounds/" + Champ + soundType + ".mp3"); public var mySound:Sound = new Sound(); public var soundChannel1:SoundChannel = new SoundChannel(); public function button() { btn1.addEventListener(MouseEvent.MOUSE_DOWN, btn1Down); btn1.addEventListener(MouseEvent.MOUSE_UP, btn1Up); } function btn1Down(e:MouseEvent){ trace("click"); Champ = "Akali."; soundType = "joke"; mySound.load(soundRequest); soundChannel1 = mySound.play(); } function btn1Up(e:MouseEvent){ trace("up"); } } }
Last edited by MJTheOne; 12-27-2010 at 10:07 AM.
-
Nevermind I fixed it.
The Request needs to be moved to the btn Function.
-
Ok so apparently I didn't fix it.
Im making this class so I dont have to type 100s of lines of code, but the solution I had, was no actual solution keeping the class function in mind.
So please help me out here:
Actionscript Code:
package { import flash.display.*; import flash.events.*; import flash.net.*; import flash.media.*; public class soundClass extends MovieClip { public var akaliLaugh01:MovieClip; public var Champ:String = new String(); public var soundType:String = new String(); public var soundRequest:URLRequest = new URLRequest("SoundsMP3Revised/" + Champ + soundType + ".mp3"); public var mySound:Sound = new Sound(soundRequest); public var soundChannel01:SoundChannel = new SoundChannel(); public var soundPosition:Number; public function soundClass() { akaliLaugh01.addEventListener(MouseEvent.MOUSE_DOWN, akaliLaugh01Down); soundPosition = soundChannel01.position; } function soundCompleteHandler(e:Event){ soundPosition = 0; } function akaliLaugh01Down(e:MouseEvent):void{ Champ = "Akali."; soundType = "laugh1"; mySound.load(soundRequest); if(soundPosition == 0){ soundChannel01 = mySound.play(); soundPosition = 1; } soundChannel01.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); } } }
Thx in advance
-
Got something that works. In your case, create a string variable and pass "SoundsMP3Revised/" + Champ + soundType + ".mp3" into it. Then pass that string variable into the URLRequest method like I do below.
Actionscript Code:
package { import flash.display.Loader; import flash.net.URLRequest; import flash.display.MovieClip;
public class Test extends MovieClip { public function Test() { var url:String = "ProjectileSimulation4.swf"; var myLoader:Loader = new Loader(); myLoader.load(new URLRequest(url)); addChild(myLoader); } } }
-
I'm really sorry, but I have no clue what u mean 
Next to that I found out it's possible to extend one Class to another.
So I started trying that and came up with this:
Actionscript Code:
package { import flash.display.*; import flash.events.*; import flash.net.*; import flash.media.*; public class orangeButton extends MovieClip { public var Champ:String = new String(); public var soundType:String = new String(); public var soundRequest:URLRequest; public var mySound:Sound = new Sound(soundRequest); public var soundChannel01:SoundChannel = new SoundChannel(); public function orangeButton() { this.stop(); this.addEventListener(MouseEvent.MOUSE_DOWN, buttonDown); this.addEventListener(MouseEvent.MOUSE_OVER, buttonOver); this.addEventListener(MouseEvent.MOUSE_OUT, buttonOut); this.addEventListener(MouseEvent.MOUSE_UP, buttonUp); } function buttonOver(e:MouseEvent){ this.gotoAndStop(2); } function buttonOut(e:MouseEvent){ this.gotoAndStop(1); } function buttonDown(e:MouseEvent){ soundRequest = new URLRequest("SoundsMP3Revised/" + Champ + soundType + ".mp3"); mySound.load(soundRequest); soundChannel01 = mySound.play(); this.gotoAndStop(3); } function buttonUp(e:MouseEvent){ this.gotoAndStop(2); } } }
Actionscript Code:
package { import flash.display.*; import flash.events.*; import flash.net.*; import flash.media.*; public class soundClass extends orangeButton { public var akaliLaugh01:MovieClip; /* public var Champ:String = new String(); public var soundType:String = new String(); public var soundRequest = new URLRequest("SoundsMP3Revised/" + Champ + soundType + ".mp3"); public var mySound:Sound = new Sound(soundRequest); public var soundChannel01:SoundChannel = new SoundChannel(); public var soundPosition:Number; */ public function soundClass() { akaliLaugh01.addEventListener(MouseEvent.MOUSE_DOWN, akaliLaugh01Down); akaliLaugh02.addEventListener(MouseEvent.MOUSE_DOWN, akaliLaugh02Down); mySound.addEventListener(IOErrorEvent.IO_ERROR, onSoundIOError, false, 0, true); //soundPosition = soundChannel01.position; } function onSoundIOError(e:IOErrorEvent){ trace("An Error Occured and it looked like this.", e.text); } /*function soundCompleteHandler(e:Event){ soundPosition = 0; }*/ function akaliLaugh01Down(e:MouseEvent){ Champ = "Akali."; soundType = "laugh1"; /* mySound.load(soundRequest); if(soundPosition == 0){ soundChannel01 = mySound.play(); soundPosition = 1; } soundChannel01.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); */ } function akaliLaugh02Down(e:MouseEvent){ Champ = "Akali."; soundType = "laugh2"; } } }
It plays the file once, the second button doesnt work (after the first one is pressed, it does work if u start with it but then the first button doesnt work), and even though the file gets played after pressing the button I get this Error:
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
at orangeButton()
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
at orangeButton()
at soundClass()
Thx in advance
Last edited by MJTheOne; 12-27-2010 at 04:57 PM.
-
-
Not many success
I can't determine if the flash player loads the sound file because loading and playing is not allowed when file is local (http://www.adobe.com/livedocs/flash/...dia/Sound.html).
Anyway, this is my fixing code. This eliminates all errors, only the file is not playing, probably because of the security limitation. I load all sound from the document class. The orangebutton02.as only holds how the movie clip will behave when the user roll his mouse over, click, etc.
Actionscript Code:
package { import flash.display.MovieClip; import flash.events.Event; import flash.events.MouseEvent; import flash.display.Loader; import flash.net.URLRequest; import flash.media.Sound; import flash.media.SoundChannel;
public class Main extends MovieClip { public var urlToSound:String; public var mySound:Sound = new Sound(); public var sndChannel:SoundChannel = new SoundChannel(); public function Main() { //prevent error #1009 addEventListener(Event.ADDED_TO_STAGE, init); } public function init(e:Event):void { removeEventListener(Event.ADDED_TO_STAGE, init); //start all your coding here var Champ:String; var soundType:String; akaliLaugh01.addEventListener(MouseEvent.CLICK, akaliLaugh01Down); akaliLaugh02.addEventListener(MouseEvent.CLICK, akaliLaugh02Down); //assign functions to buttons function akaliLaugh01Down(e:MouseEvent):void { Champ = "Akali."; soundType = "laugh1"; urlToSound = "sounds/" + Champ + soundType + ".mp3"; } function akaliLaugh02Down(e:MouseEvent):void { Champ = "Akali."; soundType = "laugh2"; urlToSound = "sounds/" + Champ + soundType + ".mp3"; } function onClick(e:MouseEvent):void { mySound.load(new URLRequest(urlToSound)); //create event listener to play sound once sound is loaded mySound.addEventListener(Event.COMPLETE, onComplete); } function onComplete(e:Event):void { //Play loaded sound sndChannel = mySound.play(); trace(mySound); } } }//end class }//end package
You should also enable Permit Debug in the Flash publish settings so Flash will tell you exactly at what line the error appears.
-
Nothing happened in the link you posted so I'm gonna say what I noticed in your first post.
PHP Code:
public var Champ:String = new String(); public var soundType:String = new String(); public var soundRequest:URLRequest = new URLRequest("sounds/" + Champ + soundType + ".mp3")
This code ran when you created an instance of that class and it's the first piece of code that ran. When you created the soundRequest variable you combined "sounds/" with the Champ and soundType variables and ".mp3". The only problem is that Champ and soundType are blank strings when you create them. So pretty much soundRequest becomes "sounds/.mp3".
PHP Code:
Champ = "Akali."; soundType = "joke"; //soundRequest = "sounds/" + Champ + soundType + ".mp3"; mySound.load(soundRequest);
Then in this part you set the string variables to the proper values I assume, but you did not update soundRequest so the mySound is trying to load a file with a path of "sounds/.mp3". So maybe you can try adding the commented line I added in the code and see if it works.
-
The thing is, that solution doesnt make sense. I mean if you look carefull you might as well just type : soundRequest = "sounds/Akali.joke.mp3". Why should I use the variables, if I parse the strings into the file path inside the button?
What I'm trying to create is an overall soundRequest which would get changed by pressing a button. Thats why I tried making 2 classes. And as stated in my previous post, this does work, one time.
And weird that the download doesnt work, I tried it again and it seems to work.
Still thx for the reply!
-
For those how are interested.
I fixed it quite simply. I replaced Champ and soundType with this.name
The only thing I had to do now was have the exact same instance name as the filename and done
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|