PDA

View Full Version : parsing commented strings from Flash to JSFL


luxe
04-05-2007, 01:59 PM
Ok. this is a little more complicated than it seams....

In flash I have an XML object that gets converted to a string via .toString() and needs to be parsed as a variable within MMExecute(). However when I try that it keeps on telling me that it is not a literal string or syntx error.
This is simplified to what I have inside Flash:...

var myXML=new XML('<node label="someLabel"><node2></node2><node>');
var xmlStr = myXML.toString();

var executeStr = 'var newStr = \"'+xmlStr+'\"; fl.trace(newStr);';
MMExecute(executeStr );


...However if I do....


var xmlStr = '<node label="someLabel"><node2></node2><node>';

var executeStr = 'var newStr = \"'+xmlStr+'\"; fl.trace(newStr);';
MMExecute(executeStr );


...there is no problem.

I have tried everything I can think of and evey kind of concacting strings with variables and alternating between single and double commas with no luck.

Please someone help..no seriously, please do.

Thanks in advance.

slopps
04-08-2007, 04:50 AM
It's the quotations around some label that's messing you up. If you trace the executeStr, you get:
var newStr = "<node label="someLabel"><node2 /><node /></node>"; fl.trace(newStr);

which will end in error as there are no \'s in front of the double quote marks around some label.

executeStr, when traced should read:
var newStr = "<node label=\"someLabel\"><node2 /><node /></node>"; fl.trace(newStr);
for this to work.

So in essence, the XML toString() method isn't inserting the required "\" you need for your purposes. Looks as if you'll have to write a function to insert them where needed for this to work.

slopps
04-08-2007, 06:18 AM
Actually...I'm an idiot and this is all you need to do:

var myXML=new XML('<node label="someLabel"><node2></node2><node>');
var xmlStr = myXML.toString();
var xmlStr = "\'" + xmlStr + "\'";
trace("XML string is: " +xmlStr);

var executeStr = 'var newStr = '+xmlStr+'; fl.trace(newStr);';
trace("executeStr is: " + executeStr);
MMExecute(executeStr);

It was just a matter of adding the ' marks around the xml text...

what's funny, is that I'm stupid and spent time writing a function to insert those slashes before I realized that.:rolleyes:

luxe
04-11-2007, 08:12 PM
:) Hay many thanks slopps! Sorry to hear that you wrote out that function b4 your mega logic kicked in. I've done some simple tests on my side and it seems to work great. Just have to implement it into the main app now...

Would be realy nice if it were possible to parse arrays, objects, etc.. in this way. I think I now the only one who would agree on this one.

But wicked thanks again for your help - magic! I owe you one.

slopps
04-11-2007, 11:22 PM
;) Cool, glad it works!

And yea, mega logic indeed...aka common sense. I dunno wtf I was thinking. hah