• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Animate read variables in PHP page and print on screen

New Here ,
May 03, 2021 May 03, 2021

Copy link to clipboard

Copied

Hello

I wanted Animate to read variables (text) from a PHP page (echo $word;) and print them on the screen.
I had that functionality working in Flash / ac3, but now with Animate I can't.
I can't find any clues how to do it in the forums about Animate.
I'm asking for your help.
Thanks!

 

TOPICS
ActionScript

Views

618

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 04, 2021 May 04, 2021

Copy link to clipboard

Copied

var xmlhttp;

var tf = this.your_text_field;

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) {
tf.text = xmlhttp.responseText;
}
}

xmlhttp.open("GET", "your_php_path_file.php", true);
xmlhttp.send();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

Hello

Kglad, Adobe Community Professional

It works! Thanks a lot!

You guys are awesome, great company.

I leave simplified code/example:

 

PHP:   s1.php

<?php
$texto_1="Olá Arbor!";
echo $texto_1;
?>

 

ACTION:

var tf = this.texto_1;

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) {
tf.text = xmlhttp.responseText;
}
}

xmlhttp.open("GET", "s1.php", true);
xmlhttp.send();

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

good to hear

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

LATEST

Hi Kglad
Adobe Community Professional

After you taught me how to print a variable coming from PHP (text_1) in Animate, I ask you to help me print several variables.

 

The result from PHP/MySQL, converted to XML is this:

 

<?xml version="1.0" encoding="UTF-8"?>
<WORDS>
<VARBOR>text_1</VARBOR>
<VARBOR>text_2</VARBOR>
<VARBOR>text_3</VARBOR>
<VARBOR>text_4</VARBOR>
</WORDS>

 

I had it working in Flash / ac3 as well, but now with Animate I can't.

Thanks!

--------------------------

I leave the code used in Flash:

 

import flash.text.*;

var myXML:XML;
var myLoader:URLLoader = new URLLoader();

myLoader.load(new URLRequest("https://arbor.pt/arbor/arbor_1/palavras_arbor_1.php"));

myLoader.addEventListener(Event.COMPLETE, processXML);

 

function processXML(e:Event):void
{
myXML = new XML(e.target.data);

for (var i:int = 1; i<myXML.*.length(); i++)
{

var vtexto:String = "texto" + [i];

var formatacao:TextFormat = new TextFormat(); // Criacao do objecto de formatacao palavras

formatacao.font = "Arial"; // Definir a fonte
formatacao.size = 18; // DefInir tamanho
formatacao.color = 0xFFFFFF; // Definir cor do texto GERAL

var cxTexto:TextField = new TextField();

addChild(cxTexto);

this[vtexto].defaultTextFormat = formatacao;
this[vtexto].text = myXML.VARBOR[i];
addChild(this[vtexto]);

}
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines