Thursday, 12 August 2010

DIV again

OK, next problem.

I realised that I very stupidly, and I won't say too much about the details, put, shall we say...sensitive info...right there in the viewable source of the html file. Pretty much rendering the whole thing completely useless.

Rather than make large and potentially catastrophic changes to the flash file, I want to tell the html file to hide the info when it has finished passing it to the swf, using DIV tags.

I have recorded on this blog how to change attributes, but forgot to mention how to change the stuff between the div tags! Stupid me. I know I worked it out before, but now I have forgotten and will have to do the whole thing all over again.

But this time, I will, insha Allah, record it for posterity.


<script type="text/javascript">
function alterTags() {
var tTag = document.getElementById("tElement");
tTag.innerHTML = "tag content";
}
</script>
<div id="tElement"></div>


That should work.

UPDATE:

OK, that code above does work - but it won't do what I want it to. You see, the page changes according to what the DIV tags say, but when you view the source, you still get to see the original.

So I will have to make some serious changes to the Flash file.

Friday, 6 August 2010

Line breaks

OK, so...

I am entering text in a flash text field, which gets sent to a mysql database. This later gets retrieved by php, and folded into a javascript function, so that another swf can use that data.

The problem is, if there are any line breaks in the initial text, then that ends up in the javascript function, and is seen as an error.

So to solve it, I will attempt to get the php file that takes the text out of the database, to convert that line break into something that the javascript function can stand, and that the swf can interpret.

Continuation -

Yeah, that worked. First I tried nl2br, which is supposed to put html linebreak tags where the line breaks are, although I din't see this effect. But this would have required me to make changes to my flash file.

So I used:

$lineBreaks = Array("\n","\r");
$iQuestion = ...get text from MySQL database
$oQuestion = str_replace($lineBreaks,'\u000d',$iQuestion);

$lineBreaks is an array of possible ways in which the line breaks may come down, I wasn't sure if this would differ depending on the user's operating system etc.

Monday, 12 July 2010

Sending/Loading... Something

I have to look this up every single time, so I thought I would put it somewhere easy to find:

function submitData() {

var nRequest:URLRequest = new URLRequest('backend.php');
nRequest.method = URLRequestMethod.POST;
var dataObj:URLVariables = new URLVariables();
dataObj.someInfo = 'some information';
nRequest.data = dataObj;
var loader:URLLoader = new URLLoader(nRequest);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(nRequest);

}

function onComplete(evnt:Event) {

var rVariables:URLVariables = new URLVariables(evnt.target.data);
trace(rVariables.someReturnedValue);

}

So in summary,

URLLoader --> URLRequest --> URLVariables

Friday, 2 July 2010

Events and Priorities

Just a note for future reference:

I tried using the priority parameter of a MouseEvent listener, to make the listener on the root get called before the listener within the movie clip, but it wouldn't work.

It was, however, able to distinguish between two listeners on the root timeline...

Wednesday, 23 June 2010

JavaScript CAN Call PHP Functions

So this is where I got to:

function gQ() {
var request = new XMLHttpRequest();
request.open("GET","getQus.php?val=What",false);
request.send();
val = request.responseText;
return val;
}

The thing is, this just gives me a query string, I can get that from PHP directly if I want one, and with less fuss.

Oh well... at least I know it can be done.

Can JavaScript Call PHP Functions? cont...

I just changed the js part to:

document.getElementsByTagName('head')[0].appendChild(script);
var vall = script.attributes.toString();
return vall;

and that got through to the Flash straightaway... what does it all mean?

Can Javascript call PHP functions?

I am beginning to wonder...

Here's the thing, I want to get some info from a MySQL database into Flash, and if I do it straight via PHP, I am going to get these really long query strings, that just might be a bit unreliable, for example if they have any ampersands in them where they shouldn't be.

But Javascript outputs arrays and objects, and these are so much tidier. If I can get the PHP to send the info to Flash as Javascript, that will be much cooler.

'include' won't work, because the output needs to depend on the parameters that Flash sends it, 'include' would simply output something as the html file is loading or whatever, and would then remain that way forever.

'Notion commotion' on Dev Shed had a solution that I can't quite get to do what I want, but here is where I am so far:

function gQ() {

var script = document.createElement('script');
script.src = 'getQus.php?val=What';
document.getElementsByTagName('head')[0].appendChild(script);
return vall;

}

and in the getQus.php file:

header("Cache-Control:no-cache");
header('Content-Type:text/javascript');
$val=$_GET['val'].' the...';
echo "vall = '$val';";


The Flash file makes an External Interface call (when a button is pressed) to the Javascript function, and puts the returned value into a text box.

What actually happens is that I have to press the button twice to get anything back.

Why, why?