Hi, I am trying to put together a product description page in Flash. Each
product will have some text fields and also some pictures. So, the issue is to
combine a thumbnail gallery with lots of data. Just to get an idea of how I
imagine it have a look at this template: ;
// read xml and display when loaded
moXML = new XML();
moXML.ignoreWhite = true;
moXML.onLoad = makeArray;
moXML.load("test.xml");
stop();
but it won't load the test.xml file that reads like this:
<?xml version="1.0" encoding="UTF-8"?>
<resultset>
<ship>
<id>1</id>
<category>sales</category>
<name>NALANI</name>
<notes>Some notes</notes>
<loa>36'36</loa>
<builder>HEYSEN</builder>
<engines>2 x 680 MAN</engines>
<year>1996</year>
<cabincount>4</cabincount>
<speedcruise>27</speedcruise>
<speedmax>32</speedmax>
<askingprice>30000</askingprice>
<askingcurrency>EUR</askingcurrency>
<numguests>6</numguests>
<propellant>motor</propellant>
<charterlow>500</charterlow>
<charterhigh>1500</charterhigh>
<chartercurrency></chartercurrency>
<beam>11</beam>
<draft>12</draft>
<hull></hull>
<consumption>255</consumption>
<fuelcapacity>16000</fuelcapacity>
<watercapacity>2000</watercapacity>
<watermaker>yes</watermaker>
<generator>SOME GENERATORS</generator>
<aircon>yes</aircon>
<crew>6</crew>
<flag>Greek</flag>
<designer>SOME</designer>
<location>GREECE</location>
<changed>20050718015506</changed>
<pix>
<pic>
<id>5</id>
<path>1.jpg</path>
<caption>General view of the deck</caption>
<category>DECK</category>
<sortnumber>1</sortnumber>
<shipid>1</shipid>
<changed>20050722192904</changed>
</pic>
<pic>
<id>6</id>
<path>4.jpg</path>
<caption>Master bedroom</caption>
<category>MASTER BEDROOM</category>
<sortnumber>2</sortnumber>
<shipid>1</shipid>
<changed>20050722192912</changed>
</pic>
</pix>
</ship>
</resultset>
Can anyone see the error? Goes without saying that the appropriate Dynamic
Text fields have been created in the movie with corresponding names (ie, notes,
builder loa, etc)
If worse comes to worst I am going to retrieve all these data using plain PHP
(without the Flash) and use the Flash just for the images.
tia
LuigiL - 23 Jul 2005 09:23 GMT
First of all: did you validate your xml? Call the file in IE and check if any
errors are reported.
2. The actionscript you found is part of a class file. The function 'Ship'
looks like a constructor function so your class file should be Ship.as
How did you implement it?
3. When a new Ship instance is created, an array gets populated with values
with this line in the code:
articles.push(thisShip);
but you don't use the array 'articles'.
5. I don't see any traces. Did you check any of the coding with trace actions?
crifty - 30 Jul 2005 08:54 GMT
OK, I simplified the actionscript down to the basics. As a matter of fact, I am
using plain PHP for the data and I only use Flash for the image gallery. The
problem is that the XML file is dynamic, it is called xml.php. You can see the
code at the end of the post.
The problem is that I must call this xml.php like this:
myPhoto.load("xml.php?id=$id");
but Flash returns an error opening the file.
Any ideas how I could make this work?
Also, ideally I would like to create thumbnails on the fly using phpThumb.php
like this:
thmb="phpThumb.php?src=uploads/<?php print $picture->contents['path'];
?>%&w=50"
but this doesn't work either. Is it a problem of calling Flash files from
Flash?
Here is the attached code for the xml.php file:
<?php
header('Content-Type: text/xml; charset=UTF-8');
print "<?xml version='1.0' encoding='UTF-8' ?>";
// render search result as xml
require_once('admin/SafeSQL.class.php');
require_once('admin/inc_db.php');
require_once('admin/settings.php');
db_marine_connect ();
print "<pix>\n";
$id = $_REQUEST['id'];
if ( $id >= 1 ) {
// print information on pix:
$searchpic = new Picture;
$searchpic->contents['shipid'] = $id;
$unsafe_query = $searchpic->search_query_string( );
$pixresult = fetch_by_search ( $unsafe_query );
while ($pixline = mysql_fetch_array($pixresult, MYSQL_ASSOC)) {
$picture = new Picture;
$picture->load_from_table( $pixline );
?>
<pic title="<?php print $picture->contents['caption']; ?>" main="uploads/<?php
print $picture->contents['path']; ?>" thmb="uploads/thumbs/<?php print
urlencode($picture->contents['path']); ?>"/>
<?php
}
// end of listed pix
}
print "</pix>\n";
?>
LuigiL - 30 Jul 2005 10:34 GMT
myPhoto.load("xml.php?id=$id");
With this line you are telling Flash to call a php-file like this:
xml.php?id=&id
meaning: &id doesn't get 'translated' into an actual number.
Variables are not declared with a $ sign in Flash, so Flash won't know what to
do.
If you want to send an id to the php-file:
myPhoto.id="1";
myPhoto.load("xml.php?id=" + myPhoto.id);
You cannot execute php-code from within Flash. When you echo the XML to Flash
you can 'include' a path to the thumb.
<picture>
<data id="0" fullsize="picture0.jpg" thumb="thumbs/picture0.jpg" />
</picture>
crifty - 31 Jul 2005 13:29 GMT
Thanks for the reply, I still can't make it work though. What I did was to
create a FlashVars param called 'myPhoto' and embed it. This is the code:
<param name="movie" value="brokerage.swf" />
<param name=FlashVars VALUE="myPhoto.id=<?php print $id;?>">
<param name="quality" value="high" />
<param name="wmode" value="transparent" />
<embed src="brokerage.swf" FlashVars="myPhoto.id=<?php print $id;?>"
width="570" height="400" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" wmode="transparent"></embed>
As you can see the id -supposedly- passed to the Flash. Based on your
suggestion, I have written at the end of the action script:
myPhoto.load("xml.php?id=" + myPhoto.id);
But still no go. Do I have to declare the use of myPhoto.id somewhere else in
the action script as well? And another thing is that I am not sure that
FlashVars is the appropriate way for a dynamically generated page. Will the
movie refresh each time is run or will it show the same $id pics at any
sequential results? I read somewhere that FlashVars is loaded only the first
time a movie is run.
LuigiL - 31 Jul 2005 14:33 GMT
Use:
<param name=FlashVars VALUE="myPhoto=<?php print $id; ?>">
You now have a variable (of datatype string) available in Flash called id and
it holds the value echoed by PHP.
myPhoto.load("xml.php?id="+myPhoto);
crifty - 31 Jul 2005 15:06 GMT
Again thanks for the reply... I tried it but still no go. It seems that even if
the id is passed to the Flash movie OK, the dynamically generated xml file is
not good enough for the Flash to work.
I suppose that I must find another solution where a normal XML file will be
written before the Flash is loaded, so the xml file called will be a plain
foo.xml.
Thanks anyway!!