Skip to main content
Known Participant
May 5, 2022
Question

Getting PHP Variable into Animate HTML5

  • May 5, 2022
  • 1 reply
  • 291 views

Hello, I am trying to figure out how to get the value of a PHP variable into an Animate HTML5 app to run an if/else statement. I have a PHP document that holds the Canvas and Javascripts to run the application. In the PHP file I define a variable before loading any of the Javascript or Canvas files:

<? $watch = "Yes" ?> //Which is really a result from a DB query.

In my ActionsScript within Animate I have the following code. This code is supposed to show a button if the PHP variable is equal to Yes, else hide it if not.

var watch = <?php echo json_encode($watch); ?>;
if (watch=="Yes"){
     this.next_btn.addEventListener("click", fl_MouseClickHandler.bind(this));
     function fl_MouseClickHandler(){
          this.parent.parent.gotoAndPlay(2);
     }
}else{
     this.next_btn.visible = !this.next_btn.visible;
}

When I run it on my webserver it hangs.  So I am not sure if I have the right code here for getting the PHP variable.  Any help would greatly be appreciated.

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
May 6, 2022

var xmlhttp;

var domParser = new DOMParser();


if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var xml_string = xmlhttp.responseText;
}
}

xmlhttp.open("GET", "date.php", true);