PDA

View Full Version : PHP, XML and Flash displaying HTML



kaplanyo
October 7th, 2007, 02:12 PM
I'm very close to having a version of the claudio scroll that uses XML output, but I'm having trouble with the < and >. I'd like to have some links or bold in the text, but getting Flash to play nice has got me.

Any advice for how I can start with Flash friendly XML output? I've tried a couple different approaches. The version that gives me the XML source with <b>'s ect.. drops out in Flash. I thought that'd be the best one.

Here's what i've tried in my php:

echo "<xml>\n";
while ($row = mysql_fetch_assoc($result)) {
echo "\t<Event dates=\"".htmlentities($row['event_date'])."\" titles=\"".htmlentities($row['event_title'])."\">".htmlentities($row['event_text'])."</Event>\n";
}
mysql_free_result($result);
echo "</xml>";

When I remove the htmlentities from the event_text, I get the '<' instead of the &lt; but then the text in Flash disappears after that tag.

Here's a snippet of my as:

var eventXML:XML = new XML();
eventXML.ignoreWhite = true;

var datesArr:Array = new Array();
var titlesArr:Array = new Array();
var eventTextArr:Array = new Array();

var fmt1:TextFormat = new TextFormat();
fmt1.font = "Bodoni Book";
fmt1.size = 13;
fmt1.color = 0x333333;
fmt1.letterSpacing = .3;

eventXML.onLoad = function(bSuccess:Boolean):Void {
if (bSuccess) {
var eventsArr:Array = this.firstChild.childNodes;
// trace(eventXML);
trace("event text array here = " + eventXML.firstChild.firstChild.toString());
trace("number of event entries = "+eventsArr.length);

// variable for holding the height of the attached clips
var hHolder:Number = 40;

for (i=0; i<eventsArr.length; i++) {
// get the xml content and store it in appropriate arrays
datesArr.push(eventsArr[i].attributes.dates);
titlesArr.push(eventsArr[i].attributes.titles);
eventTextArr.push(eventsArr[i].firstChild);
}
var eventCount:Number = eventsArr.length;
var p:Number = -1;
for (m=1; m<=eventCount; m++) {
p++;
trace("holder = "+hHolder);

// create clips in the empty container based on the number of event entries
eventContainer_mc.attachMovie("eventTextClip","eventEntry"+p+"_mc",p);

// fill the containers with content
eventContainer_mc["eventEntry"+p+"_mc"].dates.text = datesArr[p];
eventContainer_mc["eventEntry"+p+"_mc"].titles.text = titlesArr[p];

eventContainer_mc["eventEntry"+p+"_mc"].eventText.htmlText = eventTextArr[p];
eventContainer_mc["eventEntry"+p+"_mc"].eventText.html = true;
eventContainer_mc["eventEntry"+p+"_mc"].eventText.setTextFormat(fmt1);
eventContainer_mc["eventEntry"+p+"_mc"].eventText.autoSize = true;

trace(eventContainer_mc["eventEntry"+p+"_mc"]._height);
eventContainer_mc["eventEntry"+p+"_mc"]._x = 70;
eventContainer_mc["eventEntry"+p+"_mc"]._y = hHolder;
hHolder += (10+(eventContainer_mc["eventEntry"+p+"_mc"]._height));

// Set the height variables for use in the scrolling function top = eventContainer_mc._y+5;
bottom = eventContainer_mc._y + copy_mask._height - eventContainer_mc._height - space;
}
}
};

here's my online examples
http://www.workalicious.com/event_output_xml.php
http://www.workalicious.com/dev/poc_sepia_events/scrollingEvents.html

Any advice would be much appreciated. I'm going to go smash stuff with a hammer now.
Thanks,
Dave

kaplanyo
October 10th, 2007, 03:20 PM
I figured this out. After much searching and trying to learn from other posts and tutorials, I found a very simple solution for my situation. Using nodeValue and having the PHP leave the special characters in place seems to work pretty good.

eventTextArr.push(eventsArr[i].firstChild.nodeValue);
I was trying to avoid a find and replace kind of workaround, so I don't know how usuable (for all display situations) my xml out is, but it's perfect for this application. It needs some preloading, but that'll happen in the actual build. Dynamic scroller prototype (http://www.workalicious.com/dev/poc_sepia_events/)

If you're a designer (&/or developer), and you pay attention to the little details, and care about typography, this is a great way to control your type styling and tweeking in the Flash. (Even though, the typeface used in this particular example is very delicate on screen, so you may disagree with whether or not it looks sweet... anyhoo, you know what I mean about the control.)

I worked up another example here to try and understand what's possible with dyanmic content and embedded fonts. The xml side isn't there yet, but when I get a more complete version I'll post it in here for future reference. Here it is so far. (http://www.workalicious.com/dev/dynamic_text_loading/)

Digitalosophy
October 10th, 2007, 05:08 PM
Nice job man :thumb:

Dantesque
October 15th, 2007, 11:02 PM
kaplanyo. like your stuff.

kaplanyo
October 17th, 2007, 01:14 PM
Thanks guys! I'm pretty excited about the possibilities of putting this stuff together.

I was playing around with this some more and figured out how to get mutiple styles into my scrolling content areas.
http://www.workalicious.com/dev/poc_sepia_events/

Here's some more testing that help'd:
http://www.workalicious.com/dev/dynamic_text_loading/

i've entered the twilight zone and double posted those links.

affycons
October 22nd, 2007, 06:31 PM
I have an XML search feed that I would like have the results displayed like that Flash example. Might that be done the same way?