1

I have a flash movie that I need to read in a value from a PHP script in order to set which frame it starts from, I am using the following code:

if (loaded == total) {
        var lvContent = new LoadVars();
        lvContent.load("http://MY URL/Includes/getID.php");             
        trace("Who: " + lvContent.pageID);       
        lvContent.onLoad = function() {
            if (lvContent.pageID != "29") { //If it's the home page then play the full animation. If not .. don't.
                _root.gotoAndPlay(2);

            }else{
                _root.gotoAndPlay(90);
            }
        }      
    }

The problem is this is not working - it won't get into the load event. If I run the PHP manually I get "&pageID=29". If I debug this locally I get "Who: undefined" in the trace output window. From all the example I have read, I seem to be doing this correctly but it just doesn't seem to be working.

Flash: CS5 using Actionscript 2.0

Can someone take a look and let me know where I am going wrong please?

Thanks in advance.

2 Answers 2

3

You are defining the onLoad event after loading the contents. I don't think that can work.

Try

if (loaded == total) {
        var lvContent = new LoadVars();

        lvContent.onLoad = function() {
            if (lvContent.pageID != "29") { 
        //If it's the home page then play the full animation. If not .. don't.
                _root.gotoAndPlay(2);

            }else{
                _root.gotoAndPlay(90);
            }
        }    
        lvContent.load("http://MY URL/Includes/getID.php");             
        trace("Who: " + lvContent.pageID);        
    }
Sign up to request clarification or add additional context in comments.

3 Comments

load() is asynchronous, so the order may not be the issue here - but calling load after assigning onLoad is preferred nevertheless. He should be tracing pageID from the onload handler; that too after making sure that the load was success.
Good point, wasn't aware flash runs things on a procedural basis. This has now got the onLoad event firing. The variable still came back as undefined but when I started using this. instead of lvContent. inside the onLoad, that sorted my issue. Many thanks, I have marked this as the answer as it got me on the right tracks.
@Amarghosh Thanks for the advice, have implemented some checking as well in the onLoad, just to be safe.
3

You're tracing pageID before it is loaded; try this

var lvContent = new LoadVars();
lvContent.onLoad = function(success:Boolean) {
  if(!success) {
    trace("Failed to load");
    return;
  }
  trace("Who: " + lvContent.pageID);//trace from the onLoad handler
  if (lvContent.pageID != "29") 
    _root.gotoAndPlay(2);
  else
    _root.gotoAndPlay(90);
}
lvContent.load("http://MY URL/Includes/getID.php");

2 Comments

Thanks for that, have implemented the success stuff in now. This is what you get when you copy and paste code, trace's in the wrong place and dodgy code :)
+1 tracing pageID inside the onLoad handler is the correct way, I overlooked that.

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.