views:

92

answers:

2

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.

+4  A: 

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!

Badabam
A: 

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.

Cinegod