2

I am working on a random number generator in PHP and I want to send the result to the AS3 (it is much complicated but this is the main purpose)

PHP:

<?php
    function random() {
      calculating it...sql query ...blabla
      return $randomNumber;
    }
    print "randomNumber=".random();
?>

AS3:

var loader:URLLoader = new URLLoader();
var myRequest:URLRequest=new URLRequest("mylink");  
function randomPhp():void {     
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    loader.addEventListener(Event.COMPLETE, completeRandom);
    loader.load( myRequest );
}
function completeRandom(e:Event):void {
   winner=e.target.data.randomNumber;
   loader.removeEventListener( Event.COMPLETE, completeRandom );
}

The first time it generates a random Number but after that it's not changing if I call it multiple times. It's like if it creates an instance in the cache.I don't know how to fix this or reset it. And if I run my project and in the time I delete the whole PHP , the AS3 is running like nothing happened. Please HELP!!!

1 Answer 1

2

Funny enough you will have to add a RandomNumber to get your RandomNumber ;) or better a timeStamp to the URLRequest! Otherwise you will get the cached Request! Why do you need the random number from php? and not just make it in as3?

URLRequest("mylink"+"?"+new Date().getTime());

or like i said a ...+"?"+Math.random()*1000);

Sign up to request clarification or add additional context in comments.

3 Comments

cause I'm building a wheel of fortune app and the percentages are stored in a database and I need PHP to access it and the request was to generate from php so the user cannot write his own winner number.
THX !!! It works :D but it's not eating my resources that there are a lots of instances ? Is there a method to clean them up?? Or the GC will do that. Cause I'm woried about crushing in long time term.
The gc will take care of that. Since its the correct answer pls mark it as accepted, thats how this site works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.