View Full Version : flash ignoring "\n" when loaded from LoadVars
JoshuaJonah
February 25th, 2006, 02:06 PM
ok, Flash is making mad again. If i do something simple like this:
var sometext:String = "blahblahblahblah \n blahblahblah";
some_textbox.html = true;
some_textbox.htmlText = sometext;
It work's great, says:
blahblahblahblah
blahblahblah
But if i load the text via LoadVars, it ignores my "\n"s:
var dbtext:LoadVars = new LoadVars();
dbtext.sendAndLoad("somephpfile.php", dbtext)
dbtext.onLoad = function(){
var sometext:String = dbtext.loadedtext;
some_textbox.html = true;
some_textbox.htmlText = sometext;
}
duzn't work, says this:
blahblahblahblah \n blahblahblah
bigmtnskier
February 25th, 2006, 02:16 PM
What is the code in somephpfile.php?
JoshuaJonah
February 25th, 2006, 02:25 PM
for the sake of this example(which is fake by the way), the actual file im working with is huge.
<?php
$blah = "blahblahblahblah \n blahblahblah"
echo "loadedtext=".$blah
?>
JoshuaJonah
February 25th, 2006, 02:29 PM
well, i guess the php isn't really that big. Heres the real file(sans password:)):
<?php
require_once('classes/database.php');
$hostname = 'localhost';
$username = 'news';
$password = 'xxxxx';
$db = new Database($hostname, $username, $password, 'jj');
$sql = 'select * from news';
$result = $db->query($sql);
$total = $result->num_rows;
$count = 1;
while ($row = $result->fetch_assoc()) {
$thenews .= '&date'.$count. '=' .$row['date'].'&type'.$count. '=' .$row['type'].'&body'.$count. '=' .$row['body'].'&link'.$count. '=' .$row['link'];
$count++;
}
$truecount = $count-1;
echo 'total='.$truecount.$thenews;
$db->close();
?>
bigmtnskier
February 25th, 2006, 02:33 PM
try this:
<?php
$blah = "blahblahblahblah \\n blahblahblah"
echo "loadedtext=".$blah
?>
I think you need the double backslash in there so flash still sees it.
-bigmtnskier :)
JoshuaJonah
February 25th, 2006, 02:37 PM
ok, but flash is tracing the backslash, it's also putting it in the textfield
JoshuaJonah
February 25th, 2006, 02:43 PM
ok, if i send it:
<?php
$blah = "blahblahblahblah \n blahblahblah"
echo "loadedtext=".$blah
?>
It goes to next line
but if i put:
<?php
$blah = "blahblahblahblah \\n blahblahblah"
echo "loadedtext=".$blah
?>
It shows "blahblahblahblah \n blahblahblah" in the text field.
Why is is passing "\n"s as "\\n" when i'm pulling it from MySQL? Ok i'm gonna try using stripslashes in php.
JoshuaJonah
February 25th, 2006, 02:45 PM
ok, when i strip them it strips ALL the slashes so the texfield is now displaying: "blahblahblahblah n blahblahblah"
JoshuaJonah
February 25th, 2006, 02:52 PM
you know how to make a php function that will only strip the first slash if two are found in a row?
Edit: ok i made a function like this:
function fix($text) {
$text = str_replace("\\", "\", $text);
return $string;
}
edit again: why is this not working, it's like it doesn't like the slashes in the function
JoshuaJonah
February 25th, 2006, 03:04 PM
yay!.... i just changed it to:
function fix($text) {
$text = str_replace("\\n", "\n", $text);
return $string;
}
bigmtnskier
February 25th, 2006, 06:13 PM
Glad you got it fixed :)
Immulsifier
February 26th, 2006, 09:43 AM
Could have used \r instead of \n and flash would have picked this up as a new line.
JoshuaJonah
February 26th, 2006, 10:20 AM
umm.... so does \n .....?
Immulsifier
February 26th, 2006, 10:38 AM
Yes but you wouldnt have had to run it thought that function to strip off slashes.
JoshuaJonah
February 26th, 2006, 10:44 AM
But the file would still be littered with \n's beause of the textfield i was entering the text with.
I ended up just stripping everything then using php to automatically insert \n's using a wordwrap script.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.