all groups > flash (macromedia) > september 2007 >
You're in the

flash (macromedia)

group:

Profile opening file


Profile opening file Richard181
9/7/2007 6:45:29 PM
flash (macromedia):
i am having some trouble opening a file.
i fallowed a tutorial step by step but when i try to test my movie i get this
error

Error opening URL 'file:///C|/flashtest/undefined'

i have attached the code so you can see it.
in the directory i have the fallowing files.

songs.mp3
mp3Player.as
mp3Player.fla

and a few songs




//Setup sound object
var s:Sound = new Sound();
s.onSoundComplete = playSong;
s.setVolume(75);

// array of songs
var sa:Array = new Array();

// Curently playing song
var cps:Number = -1;

// load the songs XML
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function(){
var nodes:Array = this.firstChild.childNodes;
for(i=0;i<nodes.length;i++){
sa.push(nodes[i].attribute.url);
}
playSong();
}

xml.load("songs.xml");

// Play the MP3 file
function playSong()
{
if(cps==sa.length-1){
cps = 0;
s.loadSound(sa[cps],true);
}else{
s.loadSound(sa[++cps],true);
}
}
Re: problem opening file Richard181
9/7/2007 7:54:42 PM
Re: problem opening file clbeech
9/7/2007 8:18:02 PM
I think the problem here is in the 'playSong' function, provided that the XML
file is providing the correct 'locally' relative urls, or your pulling them
form a server you have access to online, and the directory path is correct.

the line:

s.loadSound(sa[++cps], true);

is incorrect, you have the increamentor on the worng side of the variable, and
I don't think this should be done within the array accessor. you should wirte
this as:

cps++;
s.loadSound(sa[cps], true);

but actually you should reduce the function to:


function playSong() {
if(cps<sa.length){
cps++;
}else{
cps=0;
}
s.loadSound(sa[cps],true);
}
Re: problem opening file Richard181
9/7/2007 9:53:26 PM
i have all of my content in a

c:\flashtest\

do I'm using my own computer no server nothing else include.

Re: problem opening file clbeech
9/7/2007 11:14:51 PM
great, then the url attribute in your XML file is set to the local directory
path? if the sound files are not in a folder then the path should simply be the
name of the file.

and did you see the code change above? this may have alot to do with it not
accesing the file if the path is correct.
Re: problem opening file Richard181
9/9/2007 1:42:25 AM
yes i did changed the code and the same problem happens, i get the same error,

Re: problem opening file Richard181
9/9/2007 11:22:38 PM
Re: problem opening file DeMolen
9/14/2007 12:00:00 AM
Hi Richard181 - were/are you following Lee Brimelow's mp3Player tutorial on The
Flash Blog? I've been doing the same tutorial and recognise the coding. I've
come up against this same problem, but during the 3rd part of the tutorial. The
code you've shown here is from part 1 and I can see some tiny mistakes which
may make a difference.

1. This is really picky, but for clarity's sake and to keep the same line
numbers as with Brimelow's original keep { and } brackets on their own separate
lines.
2. Line 18 should read - for(var i=0;i<nodes.length;i++) - you missed the
'var' out. (Push the } closing bracket to the next line on its own.)
3. This may make no difference, but you have extra spaces in line 20 which
weren't in the original, thus:
- sa.push(nodes[i].attributes.url); - I don't know ActionScript well enough to
know whether this effects the end result, but it's worth a try.
4. At the end of line 28 you're missing ':Void', it should read - function
playSong():Void
5. Again it's spaces, which may or may not be important:
Line 30: if(cps == sa.length-1) - space between 'cps' and '==' and 'sa.' etc.
Line 33: s.loadSound(sa[cps], true); - no spaces except before 'true'
Line 37: s.loadSound(sa[++cps], true); - the same, no spaces except before
'true'

I hope that helped. At this stage everything worked for me. It's something
I've probably done wrong during Tutorial 3 that's caused a problem, but I'm
darned if I can find out what.

Any help would be gratefully received!!!

Greetings from Amsterdam

Re: problem opening file clbeech
9/14/2007 1:58:41 PM
OK richard, I think I've found your problem, and have tested this and it does
function now. the 'sa.push()' statement is incorrect, the property should be
'attributes' with an 's'.

@DeMolen: I'm afraid you are incorrect, sorry.
1) No this does not matter. and {} do not need to be on separate lines, in
fact you could put all the code on one line if you wanted, it's a matter of how
Flash parses the information, by looking for specific markers in the string
sequence, spaces do not matter as well.
2) No this doesn't matter either, although it is proper and best practice, but
the variable 'i' will still be interpreted as a number upon the assignment of 0.
3) No spaces don't matter. But you we're closer with this statement, having
the correct tag: 'attributes'
4) 'function():Void' implies the 'return' type for a function and again,
doesn't matter in this case, however again, best practice but not necessary.
5) No doesn't matter.

The forums use [ ] 'tags' for text stylings 'i' within the tag represents
italics. You should paste code into the 'attach code' window.

@Richard, here is the corrected code. If this still doen't work, I can upload
the folder, that I've tested from so that you can compare document structures,
and the XML. you can determine what you are receiving from the XML file by
uncommenting the trace statements in the code below, to help debug:


//Setup sound object
var s:Sound = new Sound();
s.onSoundComplete = playSong;
s.setVolume(75);

// array of songs
var sa:Array = new Array();

// Curently playing song
var cps:Number = -1;

// load the songs XML
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function(){
//trace(this);
var nodes:Array = this.firstChild.childNodes;
for(var i=0;i<nodes.length;i++){
sa.push(nodes[i].attributes.url);
}
//trace(sa);
playSong();
}

xml.load("XMLmp3assets.xml");

// Play the MP3 file
function playSong() {
if(cps<sa.length-1){
cps++;
}else{
cps=0;
}
s.loadSound(sa[cps],true);
}
AddThis Social Bookmark Button