0

I have some values in a loop.php that generate a link like "page.php?id=1" "page.php?id=2" ecc.

I need to pass the value of "id" into actionscript3, who read a link page.php like this:

var myVars:URLVariables = new URLVariables(); 
myVars.flashVar = "myValue";

var myRequest:URLRequest = new URLRequest("page.php");
myRequest.method = URLRequestMethod.POST;
myRequest.data = myVars;

var myLoader:URLLoader = new URLLoader();
myLoader.addEventListener(Event.COMPLETE, completeHandler);
myLoader.load(myRequest);

function completeHandler(e:Event){
    var receiveVars:URLVariables = new URLVariables(e.target.data);


    vartxt1.text = receiveVars.phpVar1;

the problem is that i could change the link in actionscript like this:

var myRequest:URLRequest = new URLRequest("page.php?id=1");

but the problem is that is a static link, and if my value is changing to "4", then the link is working always with the value of "1".

i have think that maybe i could write an .xml with the value, and put actionscript to read that file...practically:

page.php?id=1 => page.xml.php (writing the xml) => redirect to page-with-swf-file.html

and when i'm on the page-with-swf-file.html i read the page.xml.php for the "id", and then load all the rest of the data that i need.

Is there an easier way of doing all this go-forward then go-back...?

hakre
  • 193,403
  • 52
  • 435
  • 836
Leon
  • 51
  • 8
  • why not flashvar the link in. http://stackoverflow.com/questions/4671867/how-do-i-access-flashvars-in-as3-and-add-them-to-an-existing-text-field – Orangepill Jul 19 '13 at 08:33
  • i have look in the flashvar link, and then in another link from that page... Ok, let's say i use flashvars so that from html the swf is getting the data, but how i could send the data to html from the php in the first place? page.php?id=2 => page-with-swf-file.html .... i think i could nest a php function in the html file, with a value from a session..but all it seem smelly ...btw thanks .. now i have 2 solutions, even if both are complicated – Leon Jul 19 '13 at 08:45
  • 1
    Generally in programming there always is an easier way, however, what is thought of being easier is highly subjective. You are better adviced asking something more concrete, e.g. what bothers you most and what you would prefer instead. – hakre Jul 21 '13 at 10:05

1 Answers1

0

Is page.php a valid link as well? Just off the top of my head, some ways to do it:

  • Flash contacts page.php, and it returns an array of all the values (id=1, id=2...)
  • Flash contacts another page that returns an array of all the values
  • Flash controls the generates the variables (i.e. in a loop do "page?id=" + i)
  • Flash just starts with "page?id=1" and in the return, php tells it the next page
  • Php passes all the values to flash vars when writing the embed code for the swf
  • Php writes all the values to an xml files, and flash loads it
divillysausages
  • 7,883
  • 3
  • 25
  • 39
  • thank you for the answer, even if a bit late :), in a index2.php i've put the index3.php?id=2 as a link. in the index3 i've make that i've write with fopen/fwrite to a file id_number.txt, the value of id, and with a redirect to page.php. In the page.php, is reading the external file id_number.txt, and load all the data who is needed for the actionscript. Until now all is going well, except i do not know how to deal with the empty values, because actionscript is giving me an error, even php it gives me an Notice...hmm.. some ideas? – Leon Jul 19 '13 at 12:38
  • that depends on what should happen when you get empty values :) if you should do nothing, then check for the empty value and if you have it, just return. Actionscript is probably giving you an error because you're trying to use a value that doesn't exist - though it depends on the error – divillysausages Jul 22 '13 at 07:40