karthikeyan wrote:

>I have a Flash Movie Templates (.swt) file containing variable elements (text)
>that has to be replaced with content by the server, in this case JSP.
>

Hi,

I did not do it with Servlets/JSP but with PHP, not with Macromedia
Flash Generator, but Swift Generator.
But the logic is exactly the same.

Imagine, You have a shop for vine, beer and softdrinks and You want to
create dynamically a Flash Movie
that shows three products (one from each category) with images randomly
from a database.

First You create Your *.swt Flash Template as kind of a skeleton with
dummy images and text variables.
You have variables like {prod1} standing for the first product's name,
{comment1} for a description and
{url1} as a link the user can click on in the flash which will redirect
to the product page or a servlet
displaying the product information identified by an id number.

And You have images (img1.jpg ...) showing the product. All will be
generated dynamically and will be
different by every click from the user.

(To avoid caching the flash movie by the browser refer it like that
<a href="intro.swf?dummy=187462947378> created by a random number or
milliseconds)

Now understand the logic behind the Generator:

When Your user clicks on the link, a servlet selects 3 products from the
database with the following SQL-statement:

"SELECT id, product_name, product_description, product_image_URL,
product_price, RAND() FROM tbl_products WHERE category='vine', LIMIT 1"
(depending on Your database engine)
You extract the field values in variables
string first_product_name = (get it from the result set)
string first_product_comment = ....
.
and repeat this for

WHERE category='beer'
WHERE category='softdrink'

If You are using images in Your movie, You now dynamically create the
images :
for every product to show You open a file input stream, read from the
'product_image_URL' (from Your database stored in a variable) into a
buffered reader (pics are binary!) and write it through a file output
stream (You have to have write permission to the directory and file!) into

img1.jpg, img2.jpg, img3.jpg

So the image NAMES allways keep the same, but the IMAGES stored under
this names change every time !
(All the images have to have exactly the same size!!!!!!)

Now Your servlet will rewrite DYNAMICALLY the configurarion file
(intro.sws ) like this:

--------- intro.sws ------------------

INPUT "/usr/local/httpd/www.drinks.com/flash/intro.swt"
OUTPUT "/usr/local/httpd/www.drinks.com/flash/intro.swf"

DEFINE IMAGE "img1.jpg" {
    FILE "/usr/local/httpd/www.drinks.com/htdocs/images/bild1.jpg"
    QUALITY 90
    WIDTH 133
    HEIGHT 100
    KEEPRATIO
}
DEFINE IMAGE "img2.jpg" {
    FILE "/usr/local/httpd/www.drinks.com/htdocs/images/bild1.jpg"
    QUALITY 90
    WIDTH 133
    HEIGHT 100
    KEEPRATIO
}
DEFINE IMAGE "img3.jpg" {
    FILE "/usr/local/httpd/www.drinks.com/htdocs/images/bild1.jpg"
    QUALITY 90
    WIDTH 133
    HEIGHT 100
    KEEPRATIO
}

SET prod1 "Dom Perignon"
SET prod2 "Guinness Dark Ale"
SET prod3 "Coca Cola"
SET comment1 "fruity, dry, very expensive"
SET comment2 "powerful and smokey"
SET comment3 "refreshing"

SET url1 "http://www.drinks.com/drinks/show_details?id=17";
SET url2 "http://www.drinks.com/drinks/show_details?id=89";
SET url3 "http://www.drinks.com/drinks/show_details?id=34";

---------------------------------------------------



... using the values stored in the variables

Now You have a system call starting a simple shell script called
"swiftstart.sh"

--------------------- swiftstart.sh ------------------------------------
#!/bin/sh
SWSFILE=/usr/local/httpd/www.drinks.com/htdocs/flash/intro.sws
/usr/local/httpd/www.drinks.com/htdocs/intro/swift-generator $SWSFILE
-----------------------------------------------------------------------

This goes for the Swift Generator.
The first line defines the startup script You have just created (no:
Your servlet has just created!!!!)
The second line calls the executable generator program with the defined
startup script as first argument

For security reasons You should place the generator of course outside
the webserver htdoc area.

You need Your webmaster to do a few necessary changes for You (file
permissions).
But those folks should work too from time to time ;-)

Max

--

Maximilian Eberl
Online Development

Astarte New Media AG
Waldstrasse 65
76133 Karlsruhe

Tel.: 0721-98554-80
Fax 0721-98554-99

mailto:[EMAIL PROTECTED]
www.astarte.de

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to