Quantcast

Forums | MacLife

You are not logged in.

#1 2008-12-03 11:39 am

Nefarious
Tuning Fork
Moderator
From: 45°22"N 84°57"W
Registered: 2002-09-30
Posts: 7998

Any flash programmers in the house ?

Can a flash movie be made with text from a database ?

That is, given a piece of text, can a program be written such that a flash movie is generated using text from a database ?    The goal is to move different text items around the screen.

Offline

 

#2 2008-12-03 12:18 pm

Onanum
Biker
From: Toronto, Ontario, Canada
Registered: 2001-08-21
Posts: 1287
Website

Re: Any flash programmers in the house ?

Hey Nefarious I'm only a beginner with Flash development, but I'll try to help.  Are you looking to access some text strings from an external database and have them displayed within swf files?  Or will this database/array of stings live within the swf file being played?  Or am I totally off the mark here? cool

Offline

 

#3 2008-12-03 12:23 pm

Nefarious
Tuning Fork
Moderator
From: 45°22"N 84°57"W
Registered: 2002-09-30
Posts: 7998

Re: Any flash programmers in the house ?

Option A:   access strings from external database.

Any info is welcome.

Offline

 

#4 2008-12-03 1:34 pm

mrreet2001
Member
From: NW Ohio
Registered: 2005-05-25
Posts: 4332
Website

Re: Any flash programmers in the house ?

do you want the strings imbedded and rendered into the movie (ie static ... one time shot)... do you want a dynamic graphic (ie you change the values of the database and the graphic is changed)

Last edited by mrreet2001 (2008-12-03 1:35 pm)


2.66Ghz QuadCore-Nehalem w/24"LED CD ---2.2Ghz BlackMB---15" 2.4Ghz MBP(work)
Dual 2.3Ghz G5 (4G Ram, 2x 250G HD)(10.5 server)--- 400Mhz G4 PM (10.4 Server)
1.5GHz Powerbook---1.6Ghz G5 iMac
"So he fels down in a poisoning gas."

Offline

 

#5 2008-12-03 2:10 pm

Nefarious
Tuning Fork
Moderator
From: 45°22"N 84°57"W
Registered: 2002-09-30
Posts: 7998

Re: Any flash programmers in the house ?

Maybe yes and maybe no.

If the strings are embedded, then I would need to know what the file size was.  I suspect that a 5 minute flash movie would be 30 MByte.

A dynamic graphic might be easier on file size, but harder on the programmer ?

Offline

 

#6 2008-12-03 11:55 pm

PHUSMC
One thumbed gimpy
From: Kent, WA
Registered: 2006-05-14
Posts: 822
Website

Re: Any flash programmers in the house ?

There are a lot of tutorials about PHP, MySQL, and Flash.  I am sure you can do this.  I've just started learning ActionScript 3.0 on my own as I am finishing an intro Flash class at school.  Seems very possible.


MacBook Pro 15.4"
2.5GHz CPU, 250GB HDD, 512MB VRAM

Offline

 

#7 2008-12-12 12:37 pm

Crontab
Member
From: Rochester, NY
Registered: 2003-01-27
Posts: 400
Website

Re: Any flash programmers in the house ?

At work I load in data into Flash movies using a php file with an xml header.  If you would like I can post an example.  Sometimes I also use swfobject to send data to the Flash movie.  This is just a simple Javascript that allows me to inject a swf on a web page.  It also has nice options such as sending data to the Flash movie.  Its pretty slick and its built into Mootools now.


Oscar Bytes My personal web site
Man I love my MacBook Pro Core 2 Duo!!!!!

Offline

 

#8 2008-12-12 12:52 pm

Nefarious
Tuning Fork
Moderator
From: 45°22"N 84°57"W
Registered: 2002-09-30
Posts: 7998

Re: Any flash programmers in the house ?

Crontab wrote:

At work I load in data into Flash movies using a php file with an xml header.  If you would like I can post an example.  Sometimes I also use swfobject to send data to the Flash movie.  This is just a simple Javascript that allows me to inject a swf on a web page.  It also has nice options such as sending data to the Flash movie.  Its pretty slick and its built into Mootools now.

Looking forward to any examples.

Offline

 

#9 2008-12-12 1:20 pm

PHUSMC
One thumbed gimpy
From: Kent, WA
Registered: 2006-05-14
Posts: 822
Website

Re: Any flash programmers in the house ?

I'm actually going to have to learn how to do this pretty soon. We are going to take random entries in a database and have the information appear in a Flash movie at random points on the movie, fading in and fading out at random times.  This should be fun.


MacBook Pro 15.4"
2.5GHz CPU, 250GB HDD, 512MB VRAM

Offline

 

#10 2008-12-12 1:42 pm

Nefarious
Tuning Fork
Moderator
From: 45°22"N 84°57"W
Registered: 2002-09-30
Posts: 7998

Re: Any flash programmers in the house ?

That's exactly what I want, PHUSMC.

Offline

 

#11 2008-12-12 7:07 pm

PHUSMC
One thumbed gimpy
From: Kent, WA
Registered: 2006-05-14
Posts: 822
Website

Re: Any flash programmers in the house ?

Nefarious wrote:

That's exactly what I want, PHUSMC.

Funny how things like that happen, isn't it?

I looked at a tutorial on reading XML into Flash, using PHP and MySQL.  PHP pulls the records and echoes out the XML based on the records it pulls.  Flash reads the XML created by PHP, and stores it for use.  Here is the tutorial I looked at: http://library.creativecow.net/articles … torial.php


MacBook Pro 15.4"
2.5GHz CPU, 250GB HDD, 512MB VRAM

Offline

 

#12 2008-12-16 2:34 pm

Crontab
Member
From: Rochester, NY
Registered: 2003-01-27
Posts: 400
Website

Re: Any flash programmers in the house ?

That's how you do it.  I have been really busy but I am hoping I can post some examples tonight.  Its really not that difficult.  From the sounds of it your tutorial covers it.  There are a couple other ways to bring data into Flash to.  However you can't really bring as much data in.  XML is the way to go.


Oscar Bytes My personal web site
Man I love my MacBook Pro Core 2 Duo!!!!!

Offline

 

#13 2008-12-16 6:18 pm

PHUSMC
One thumbed gimpy
From: Kent, WA
Registered: 2006-05-14
Posts: 822
Website

Re: Any flash programmers in the house ?

Here is what I have started so far.  I am connecting to a MySQL database which holds words that are associated with "status quo".  I am using PHP to retrieve that information, and put it in an XML format.  Then, I am parsing that XML in Flash, using ActionScript 3.0, and storing the text from the XML in an array that I will use later.  Hope this helps.  I'm learning as  I go really.

PHP to create XML:

Code:

<?php
// Connect to MySQL
$mysqli = new mysqli("localhost", "userName", "password", "database");

// Check connection
if (mysqli_connect_errno())
{
    printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
} // End if

$sql = "SELECT id, synonym FROM status_quo";

// A result was returned
if($result = $mysqli->query($sql))
{
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    echo "<status_quo>";
    
    while($row = $result->fetch_assoc())
    {
        echo "\n\t<syn>".$row['synonym']."</syn>";
    } // End while
    
    echo "\n</status_quo>";
} // End if
else
{
    printf("No result returned.");
      exit();
} // End else

// Close the connection
$mysqli->close();
?>

XML it created:

Code:

<?xml version="1.0" encoding="UTF-8"?>
<status_quo>
    <syn>The Norm</syn>
    <syn>Everyday</syn>
    <syn>The Usual</syn>
       <syn>etc...</syn>
</status_quo>

ActionScript 3.0 code

Code:

/ Loader for XML to ensure file is loaded completley
var xmlLoader:URLLoader = new URLLoader();

// Holds the XML data after it is loaded
var xmlData:XML = new XML();

// Array to hold synonyms for "Status Quo"
// from xmlData
var synArray:Array = new Array();

// Event listener for the xmlLoader
// When the XML file is done loading, fire the loadXML function
xmlLoader.addEventListener(Event.COMPLETE, loadXML);

// Load the XML file into the xmlLoader
xmlLoader.load(new URLRequest("http://localhost:8888/flash/status_quo.php"));

// Puts the XML data into the xmlData variable
// and parses it using parseXML
function loadXML(e:Event):void
{
    // Assign xmlData to the data from the
    // event that fired it
    xmlData = new XML(e.target.data);
    
    // Run parseXML
    parseXML(xmlData);
    
    // Trace out the values in the synArray after parsing it
    trace(synArray);
} // End loadXML

// Parses the XML passed to it
function parseXML(input:XML):void
{
    // XMLList that holds the text values for
    // each 'syn' element in the XML document
    var synList:XMLList  = input.syn.text();

    // Add each XML element in the XMLList
    // into the synArray
    for each(var synElement:XML in synList)
    {
        //trace(synElement);
        synArray.push(synElement);
    } // End for
} // End parseXML

MacBook Pro 15.4"
2.5GHz CPU, 250GB HDD, 512MB VRAM

Offline

 

#14 2008-12-18 10:12 am

Crontab
Member
From: Rochester, NY
Registered: 2003-01-27
Posts: 400
Website

Re: Any flash programmers in the house ?

That's exactly how you want to do it.  Parsing it to an array allows you to change the xml later and then all you would have to do in theory is alter your parsing function.  Otherwise you would be changing multiple functions and it would be complicated.

Keep in mind I program in ActionScript 3 and only have been doing this stuff a year.  Here are some tips.

Here is a handy function I use to see if a node exists in the XML.

Code:

function isset( variable:Object ):Boolean {
    return (variable != undefined);
}

// Check to see if this is an internal or external link
if (isset(f1.topics.topic.file) == true || isset(f1.topics.topic.description) == true) {
    navigation[pCount][8] = true; // true internal link
} else {
    navigation[pCount][8] = false; // true external link
}
        
// Assign data to the array.  If element does not exist in XML then variable is undefined.
if (isset(f1.topics.topic.file) == true) {
    navigation[pCount][2] = String(f1.topics.topic.file);
}

So if a node doesn't exist the value in the array is undefined.  So this allows me to do some slick stuff.  The flash movie will do different things depending on how my XML is setup.

Code:

var xmlLoader:URLLoader = new URLLoader();  // URL Loader will load in the required xml file
xmlLoader.addEventListener(Event.COMPLETE, parseTourXML); // On completion parse the xml file
xmlLoader.load(new URLRequest("navigation.php")); // XML file to be loaded for parsing.

Thats how I do it in ActionScript 3.  Now I would post my parsing function but its pretty long because there are so many variables.  If you need any tips just post back here and hopefully I can help.  In the meantime if I think of a tip I will just post here.  It seems like you figured it out though.


Basically the piece I am working on at work takes in xml and will generate a menus system all in ActionScript.  You can close and reopen the menus and its pretty slick.  Depending on the XML it will open an internal link within the Flash or an external link to a web page.  The piece preloads in SWFs or pictures to the screen for internal links.

I posted this really quick so hopefully my grammar isn't to horrendous.

Last edited by Crontab (2008-12-18 10:14 am)


Oscar Bytes My personal web site
Man I love my MacBook Pro Core 2 Duo!!!!!

Offline

 

Board footer

Powered by PunBB 1.2.6
© Copyright 2002–2005 Rickard Andersson