A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Detect URLRequest variable change?

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    3

    Detect URLRequest variable change?

    Alright, so I'm using AS3 to get variables from a plain text file. The variables are loaded, and assigned as a variable in Flash.
    Code:
    var checkNew:Timer = new Timer(2000);
    checkNew.addEventListener(TimerEvent.TIMER, reConnect);
    checkNew.start();
    function reConnect(evt:TimerEvent):void{
    	var request:URLRequest = new URLRequest("vars/vars.php?"+new Date().getTime());
    	request.method = URLRequestMethod.GET;
    	var loader:URLLoader = new URLLoader();
    	loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    	loader.addEventListener(Event.COMPLETE, completeHandler);
    	loader.load(request);
    }
    function completeHandler(evt:Event) {
    	var gamertagText = evt.target.data.gamertag;
    	addEventListener(Event.ENTER_FRAME, gamertagShow);
    	function gamertagShow(event:Event){
    		gamertagHolder.gamertag.text = String(gamertagText);
    	}
    }
    So basically as you can see here, the gamertag is loaded from a plain text PHP file and converted into a variable. What I need to be able to do is tell whether or not that variable has changed (ex. 1 changed to 2). Is there a way of doing this in AS3?

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You create a variable somewhere at the beginning of your script:
    var varChanged:String = "";
    Then after this line you write:
    var gamertagText = evt.target.data.gamertag;
    if(varChanged != null && varChanged != gamertagText)
    {
    trace("no");
    }
    else if(varChanged == gamertagText)
    {
    trace("yes");
    }
    varChanged = gamertagText;
    Last edited by cancerinform; 11-21-2009 at 08:25 PM.
    - The right of the People to create Flash movies shall not be infringed. -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center