Hello,
I have used JavaScript in the past but have not tried anything like
this. If anyone could point me to a good spot to learn how to do
this, I would greatly appreciate it.
What I am trying to do, is describe in an XML file some videos. This
file looks something like this
<videos>
<video>
<fileName>video1.flv</fileName>
<title>title1</title>
<description>This is video1</description>
</video>
<video>
<fileName>video2.flv</fileName>
<title>title2</title>
<description>This is video2</description>
</video>
..... etc.
What i would like to do is load this from the XML file, list out the
titles, and when the titles are clicked the filename is passed into my
swf file to play the different clip.
Thanks very much for any suggestions.
|
|
0
|
|
|
|
Reply
|
KDawg44 (132)
|
7/11/2007 9:07:32 PM |
|
"KDawg44" <KDawg44@gmail.com> wrote in message
news:1184188052.041347.87350@k79g2000hse.googlegroups.com...
> Hello,
>
> I have used JavaScript in the past but have not tried anything like
> this. If anyone could point me to a good spot to learn how to do
> this, I would greatly appreciate it.
>
> What I am trying to do, is describe in an XML file some videos. This
> file looks something like this
>
> <videos>
> <video>
> <fileName>video1.flv</fileName>
> <title>title1</title>
> <description>This is video1</description>
> </video>
> <video>
> <fileName>video2.flv</fileName>
> <title>title2</title>
> <description>This is video2</description>
> </video>
> .... etc.
>
> What i would like to do is load this from the XML file, list out the
> titles, and when the titles are clicked the filename is passed into my
> swf file to play the different clip.
I would parse the filenames on the server with MSXML and generate the JS
that creates the links. This could also be done with PHP, PERL, etc. (or
AJAX on the client side.) In the JS, pass the filenames to Flash in the
links' onclick handlers using SetVariable or ExternalInterface (one of these
is better supported across Flash versions than the other, but I forget
which.) The links should be hidden initially and presented only if a
suitable Flash version is detected. If using AJAX and a suitable Flash
version is not found, you should skip the XML download entirely.
|
|
0
|
|
|
|
Reply
|
David
|
7/11/2007 11:50:24 PM
|
|
On Jul 11, 6:50 pm, "David Mark" <d...@cinsoft.net> wrote:
> "KDawg44" <KDaw...@gmail.com> wrote in message
>
> news:1184188052.041347.87350@k79g2000hse.googlegroups.com...
>
>
>
> > Hello,
>
> > I have used JavaScript in the past but have not tried anything like
> > this. If anyone could point me to a good spot to learn how to do
> > this, I would greatly appreciate it.
>
> > What I am trying to do, is describe in an XML file some videos. This
> > file looks something like this
>
> > <videos>
> > <video>
> > <fileName>video1.flv</fileName>
> > <title>title1</title>
> > <description>This is video1</description>
> > </video>
> > <video>
> > <fileName>video2.flv</fileName>
> > <title>title2</title>
> > <description>This is video2</description>
> > </video>
> > .... etc.
>
> > What i would like to do is load this from the XML file, list out the
> > titles, and when the titles are clicked the filename is passed into my
> > swf file to play the different clip.
>
> I would parse the filenames on the server with MSXML and generate the JS
> that creates the links. This could also be done with PHP, PERL, etc. (or
> AJAX on the client side.) In the JS, pass the filenames to Flash in the
> links' onclick handlers using SetVariable or ExternalInterface (one of these
> is better supported across Flash versions than the other, but I forget
> which.) The links should be hidden initially and presented only if a
> suitable Flash version is detected. If using AJAX and a suitable Flash
> version is not found, you should skip the XML download entirely.
Thanks very much for the suggestions. My problem is that I am doing
this through a Content Management System and do not have the ability
to use a server side scripting language (because that would make it
waaaaay to easy and we can't have that can we?).
I can access the XML file and parse it. I would like to parse it into
variables and then access those variables through function calls. The
problem is that, on loading the page, the function calls to write part
of the page are being called before the XML parsing is loading the
variables what's written is coming up as undefined...
Any suggestions?
Thanks.
|
|
0
|
|
|
|
Reply
|
KDawg44
|
7/12/2007 5:21:37 PM
|
|
On Jul 12, 1:21 pm, KDawg44 <KDaw...@gmail.com> wrote:
> On Jul 11, 6:50 pm, "David Mark" <d...@cinsoft.net> wrote:
>
>
>
>
>
> > "KDawg44" <KDaw...@gmail.com> wrote in message
>
> >news:1184188052.041347.87350@k79g2000hse.googlegroups.com...
>
> > > Hello,
>
> > > I have used JavaScript in the past but have not tried anything like
> > > this. If anyone could point me to a good spot to learn how to do
> > > this, I would greatly appreciate it.
>
> > > What I am trying to do, is describe in an XML file some videos. This
> > > file looks something like this
>
> > > <videos>
> > > <video>
> > > <fileName>video1.flv</fileName>
> > > <title>title1</title>
> > > <description>This is video1</description>
> > > </video>
> > > <video>
> > > <fileName>video2.flv</fileName>
> > > <title>title2</title>
> > > <description>This is video2</description>
> > > </video>
> > > .... etc.
>
> > > What i would like to do is load this from the XML file, list out the
> > > titles, and when the titles are clicked the filename is passed into my
> > > swf file to play the different clip.
>
> > I would parse the filenames on the server with MSXML and generate the JS
> > that creates the links. This could also be done with PHP, PERL, etc. (or
> > AJAX on the client side.) In the JS, pass the filenames to Flash in the
> > links' onclick handlers using SetVariable or ExternalInterface (one of these
> > is better supported across Flash versions than the other, but I forget
> > which.) The links should be hidden initially and presented only if a
> > suitable Flash version is detected. If using AJAX and a suitable Flash
> > version is not found, you should skip the XML download entirely.
>
> Thanks very much for the suggestions. My problem is that I am doing
> this through a Content Management System and do not have the ability
> to use a server side scripting language (because that would make it
> waaaaay to easy and we can't have that can we?).
>
> I can access the XML file and parse it. I would like to parse it into
> variables and then access those variables through function calls. The
> problem is that, on loading the page, the function calls to write part
> of the page are being called before the XML parsing is loading the
> variables what's written is coming up as undefined...
>
> Any suggestions?
Yes. Post your code.
|
|
0
|
|
|
|
Reply
|
David
|
7/12/2007 5:37:20 PM
|
|
On Jul 12, 1:37 pm, David Mark <dmark.cins...@gmail.com> wrote:
> On Jul 12, 1:21 pm, KDawg44 <KDaw...@gmail.com> wrote:
>
>
>
> > On Jul 11, 6:50 pm, "David Mark" <d...@cinsoft.net> wrote:
>
> > > "KDawg44" <KDaw...@gmail.com> wrote in message
>
> > >news:1184188052.041347.87350@k79g2000hse.googlegroups.com...
>
> > > > Hello,
>
> > > > I have used JavaScript in the past but have not tried anything like
> > > > this. If anyone could point me to a good spot to learn how to do
> > > > this, I would greatly appreciate it.
>
> > > > What I am trying to do, is describe in an XML file some videos. This
> > > > file looks something like this
>
> > > > <videos>
> > > > <video>
> > > > <fileName>video1.flv</fileName>
> > > > <title>title1</title>
> > > > <description>This is video1</description>
> > > > </video>
> > > > <video>
> > > > <fileName>video2.flv</fileName>
> > > > <title>title2</title>
> > > > <description>This is video2</description>
> > > > </video>
> > > > .... etc.
>
> > > > What i would like to do is load this from the XML file, list out the
> > > > titles, and when the titles are clicked the filename is passed into my
> > > > swf file to play the different clip.
>
> > > I would parse the filenames on the server with MSXML and generate the JS
> > > that creates the links. This could also be done with PHP, PERL, etc. (or
> > > AJAX on the client side.) In the JS, pass the filenames to Flash in the
> > > links' onclick handlers using SetVariable or ExternalInterface (one of these
> > > is better supported across Flash versions than the other, but I forget
> > > which.) The links should be hidden initially and presented only if a
> > > suitable Flash version is detected. If using AJAX and a suitable Flash
> > > version is not found, you should skip the XML download entirely.
>
> > Thanks very much for the suggestions. My problem is that I am doing
> > this through a Content Management System and do not have the ability
> > to use a server side scripting language (because that would make it
> > waaaaay to easy and we can't have that can we?).
>
> > I can access the XML file and parse it. I would like to parse it into
> > variables and then access those variables through function calls. The
> > problem is that, on loading the page, the function calls to write part
> > of the page are being called before the XML parsing is loading the
> > variables what's written is coming up as undefined...
>
> > Any suggestions?
>
> Yes. Post your code.
<html>
<head>
<script language="javascript" type="text/javascript">
var fileName = new Array();
var title = new Array();
function importXML()
{
if (document.implementation &&
document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = createList;
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) extract()
};
}
else
{
alert('Your browser can\'t handle this script');
return;
}
xmlDoc.load("videos.xml");
}
function extract()
{
var x = xmlDoc.getElementsByTagName('video');
for (i=0;i<x.length;i++)
{
fileName[i] =
document.createTextNode(x[i].childNodes[1].firstChild.nodeValue);
title[i] =
document.createTextNode(x[i].childNodes[3].firstChild.nodeValue);
}
}
function getfileNames()
{
return fileName;
}
function getTitles()
{
return title;
}
</script>
</head>
<body bgcolor = "#FFFFFF" onLoad="javascript:importXML();">
<table border = 0 width = 221>
<tr><td align = center><a href =
"javascript:launchVideoPlayer();"><font face = verdana size = 2 color
= "#FFFFFF">Launch Video Player</a></td></tr>
<tr><td>
<script type="text/javascript">
var titles = new Array;
titles = getTitles();
document.write(titles[0]);
</script>
</td></tr>
<tr><td> </td></tr>
</table>
</body>
</html>
Thanks for any suggestions. Obviously this code is not complete for
my ultimate goal but I am just trying to parse the XML and print it
out at this point. (preferably without any of that DOM appendChild
and createElement stuff).
Thanks.
|
|
0
|
|
|
|
Reply
|
KDawg44
|
7/12/2007 6:42:39 PM
|
|
On Jul 12, 2:42 pm, KDawg44 <KDaw...@gmail.com> wrote:
> On Jul 12, 1:37 pm, David Mark <dmark.cins...@gmail.com> wrote:
>
>
>
>
>
> > On Jul 12, 1:21 pm, KDawg44 <KDaw...@gmail.com> wrote:
>
> > > On Jul 11, 6:50 pm, "David Mark" <d...@cinsoft.net> wrote:
>
> > > > "KDawg44" <KDaw...@gmail.com> wrote in message
>
> > > >news:1184188052.041347.87350@k79g2000hse.googlegroups.com...
>
> > > > > Hello,
>
> > > > > I have used JavaScript in the past but have not tried anything like
> > > > > this. If anyone could point me to a good spot to learn how to do
> > > > > this, I would greatly appreciate it.
>
> > > > > What I am trying to do, is describe in an XML file some videos. This
> > > > > file looks something like this
>
> > > > > <videos>
> > > > > <video>
> > > > > <fileName>video1.flv</fileName>
> > > > > <title>title1</title>
> > > > > <description>This is video1</description>
> > > > > </video>
> > > > > <video>
> > > > > <fileName>video2.flv</fileName>
> > > > > <title>title2</title>
> > > > > <description>This is video2</description>
> > > > > </video>
> > > > > .... etc.
>
> > > > > What i would like to do is load this from the XML file, list out the
> > > > > titles, and when the titles are clicked the filename is passed into my
> > > > > swf file to play the different clip.
>
> > > > I would parse the filenames on the server with MSXML and generate the JS
> > > > that creates the links. This could also be done with PHP, PERL, etc. (or
> > > > AJAX on the client side.) In the JS, pass the filenames to Flash in the
> > > > links' onclick handlers using SetVariable or ExternalInterface (one of these
> > > > is better supported across Flash versions than the other, but I forget
> > > > which.) The links should be hidden initially and presented only if a
> > > > suitable Flash version is detected. If using AJAX and a suitable Flash
> > > > version is not found, you should skip the XML download entirely.
>
> > > Thanks very much for the suggestions. My problem is that I am doing
> > > this through a Content Management System and do not have the ability
> > > to use a server side scripting language (because that would make it
> > > waaaaay to easy and we can't have that can we?).
>
> > > I can access the XML file and parse it. I would like to parse it into
> > > variables and then access those variables through function calls. The
> > > problem is that, on loading the page, the function calls to write part
> > > of the page are being called before the XML parsing is loading the
> > > variables what's written is coming up as undefined...
>
> > > Any suggestions?
>
> > Yes. Post your code.
>
> <html>
> <head>
> <script language="javascript" type="text/javascript">
> var fileName = new Array();
> var title = new Array();
>
> function importXML()
> {
> if (document.implementation &&
> document.implementation.createDocument)
> {
> xmlDoc = document.implementation.createDocument("", "", null);
> xmlDoc.onload = createList;
> }
> else if (window.ActiveXObject)
> {
> xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
> xmlDoc.onreadystatechange = function () {
> if (xmlDoc.readyState == 4) extract()
> };
> }
> else
> {
> alert('Your browser can\'t handle this script');
> return;
> }
> xmlDoc.load("videos.xml");
> }
>
> function extract()
> {
> var x = xmlDoc.getElementsByTagName('video');
> for (i=0;i<x.length;i++)
> {
> fileName[i] =
> document.createTextNode(x[i].childNodes[1].firstChild.nodeValue);
> title[i] =
> document.createTextNode(x[i].childNodes[3].firstChild.nodeValue);
> }
> }
>
> function getfileNames()
> {
> return fileName;
> }
>
> function getTitles()
> {
> return title;
> }
>
> </script>
> </head>
> <body bgcolor = "#FFFFFF" onLoad="javascript:importXML();">
>
> <table border = 0 width = 221>
>
> <tr><td align = center><a href =
> "javascript:launchVideoPlayer();"><font face = verdana size = 2 color
> = "#FFFFFF">Launch Video Player</a></td></tr>
> <tr><td>
> <script type="text/javascript">
> var titles = new Array;
> titles = getTitles();
> document.write(titles[0]);
How can you write something during load that isn't retrieved until
after the page loads?
> </script>
> </td></tr>
> <tr><td> </td></tr>
> </table>
>
> </body>
> </html>
>
> Thanks for any suggestions. Obviously this code is not complete for
> my ultimate goal but I am just trying to parse the XML and print it
> out at this point. (preferably without any of that DOM appendChild
> and createElement stuff).
You will have to use DOM manipulation to do this.
|
|
0
|
|
|
|
Reply
|
David
|
7/12/2007 10:10:41 PM
|
|
KDawg44 wrote:
> I have used JavaScript in the past but have not tried
> anything like this. If anyone could point me to a good spot
> to learn how to do this, I would greatly appreciate it.
>
> What I am trying to do, is describe in an XML file some
> videos. This file looks something like this
[ snip XML code ]
> What i would like to do is load this from the XML file, list
> out the titles, and when the titles are clicked the filename
> is passed into my swf file to play the different clip.
-------------------------------------------------------------------
XML file 'videos.xml':
-------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<videos>
<video>
<file>video1.flv</file>
<title>title1</title>
<desc>This is video1</desc>
</video>
<video>
<file>video2.flv</file>
<title>title2</title>
<desc>This is video2</desc>
</video>
<video>
<file>video3.flv</file>
<title>title3</title>
<desc>This is video3</desc>
</video>
</videos>
-------------------------------------------------------------------
HTML file (in same directory):
-------------------------------------------------------------------
<html>
<head>
<script type="text/javascript">
var xmlDoc;
var output = '';
function loadXML()
{
// load xml file - code for IE
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xmlDoc.load('videos.xml');
getmessage();
}
// load xml file - code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument('', '', null);
xmlDoc.load('videos.xml');
xmlDoc.onload = getmessage;
}
else
{
alert('Your browser cannot handle this script');
}
}
function getmessage()
{
// walk the 'file'-tags and make code with link to player.swf:
// <a href="player.swf?file=FILE">TITLE</a><br>DESC<br><hr>
for (var i=0; i<xmlDoc.getElementsByTagName("file").length; ++i)
{
output += '<a href="player.swf?file='
+ xmlDoc.getElementsByTagName('file')[i].childNodes[0].nodeValue
+ '">'
+ xmlDoc.getElementsByTagName('title')[i].childNodes[0].nodeValue
+ '</a><br>\n'
+ xmlDoc.getElementsByTagName('desc')[i].childNodes[0].nodeValue
+ '<br><hr>\n';
}
document.getElementById('vids').innerHTML = output;
}
</script>
</head>
<body onload="loadXML()">
<span id="vids"></span>
</body>
</html>
-------------------------------------------------------------------
Hope this helps,
--
Bart
|
|
0
|
|
|
|
Reply
|
Bart
|
7/13/2007 10:19:50 AM
|
|
On Jul 13, 6:19 am, Bart Van der Donck <b...@nijlen.com> wrote:
> KDawg44 wrote:
> > I have used JavaScript in the past but have not tried
> > anything like this. If anyone could point me to a good spot
> > to learn how to do this, I would greatly appreciate it.
>
> > What I am trying to do, is describe in an XML file some
> > videos. This file looks something like this
>
> [ snip XML code ]
>
> > What i would like to do is load this from the XML file, list
> > out the titles, and when the titles are clicked the filename
> > is passed into my swf file to play the different clip.
>
> -------------------------------------------------------------------
> XML file 'videos.xml':
> -------------------------------------------------------------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <videos>
> <video>
> <file>video1.flv</file>
> <title>title1</title>
> <desc>This is video1</desc>
> </video>
> <video>
> <file>video2.flv</file>
> <title>title2</title>
> <desc>This is video2</desc>
> </video>
> <video>
> <file>video3.flv</file>
> <title>title3</title>
> <desc>This is video3</desc>
> </video>
> </videos>
>
> -------------------------------------------------------------------
> HTML file (in same directory):
> -------------------------------------------------------------------
>
> <html>
> <head>
> <script type="text/javascript">
> var xmlDoc;
> var output = '';
>
> function loadXML()
> {
> // load xml file - code for IE
> if (window.ActiveXObject)
> {
> xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
> xmlDoc.async = false;
> xmlDoc.load('videos.xml');
> getmessage();
> }
>
> // load xml file - code for Mozilla, Firefox, Opera, etc.
> else if (document.implementation
> && document.implementation.createDocument)
> {
> xmlDoc = document.implementation.createDocument('', '', null);
> xmlDoc.load('videos.xml');
> xmlDoc.onload = getmessage;
> }
>
> else
> {
> alert('Your browser cannot handle this script');
> }
>
> }
>
> function getmessage()
> {
> // walk the 'file'-tags and make code with link to player.swf:
> // <a href="player.swf?file=FILE">TITLE</a><br>DESC<br><hr>
> for (var i=0; i<xmlDoc.getElementsByTagName("file").length; ++i)
> {
> output += '<a href="player.swf?file='
> + xmlDoc.getElementsByTagName('file')[i].childNodes[0].nodeValue
> + '">'
> + xmlDoc.getElementsByTagName('title')[i].childNodes[0].nodeValue
> + '</a><br>\n'
> + xmlDoc.getElementsByTagName('desc')[i].childNodes[0].nodeValue
> + '<br><hr>\n';
> }
> document.getElementById('vids').innerHTML = output;}
>
> </script>
> </head>
> <body onload="loadXML()">
> <span id="vids"></span>
> </body>
> </html>
>
> -------------------------------------------------------------------
>
> Hope this helps,
>
> --
> Bart
Thanks!
|
|
0
|
|
|
|
Reply
|
KDawg44
|
7/13/2007 2:39:39 PM
|
|
|
7 Replies
98 Views
(page loaded in 0.12 seconds)
|