0

I've made an empty AS 3 .flv document that has one keyframe on position 1 with this action:

on(load)

{

    var req:LoadVars = new LoadVars();    
    req.x = "y";  
    req.load("http://localhost/file.php");    
    req.onData = function(src:String) {
        req.x = src;
        req.send("http://localhost/send.php", "_self", "POST"); 
        };
}

I'm receiving numerous errors such as the on(load) is invalid. I'm trying to run the code in the beginning of the movie.

2
  • You are getting errors because it is not AS3 : I'm not sure if on(load) is AS1 or AS2, but it's definitely not AS3
    – Amarghosh
    Commented Nov 25, 2009 at 17:25
  • And you are sending the req from its onData - onData is fired only after you have send it and received the response back from server.
    – Amarghosh
    Commented Nov 25, 2009 at 17:26

2 Answers 2

4

This code is AS2, not AS3. on(load) is obsolete in AS3. In AS3, you should use something like this:

import flash.net.*;
import flash.events.*;

var loader:URLLoader;
var request:URLRequest;

function loadVars():void
{
    request = new URLRequest('your_url.php');

    loader = new URLLoader();
    loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true);
    loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
    loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError);
    loader.load(request);
}

function onComplete(e:Event):void
{
    trace("data", e.target.data);
}

function onIOError(e:IOErrorEvent):void
{
    trace("IO ERROR", e.text);
}
function onSecError(e:SecurityErrorEvent):void
{
    trace("Security ERROR", e.text);
}

This code is not tested. Read the online ActionScript 3 Documentation from Adobe for more help!

0

In AS3 you need to use URLLoader and URLRequest to load external documents into your movie. There is a great example in the live docs provided by Adobe here:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLLoader.html#includeExamplesSummary

I suggest trying that and posting your results back here.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.