I have a main SWF file, in AS3, wich works as holder/loader for many other SWF files (sections). I had to make a new section ("verano.swf"), but I did it in AS2. When I try to load it, I get the following error:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChild()
at Tabu/onCompleteHandler()
It refers to this function:
function onCompleteHandler(loadEvent:Event)
{
currentMovie = loadEvent.currentTarget.content as MovieClip;
addChild(currentMovie);
if (firstTime)
{
(root as MovieClip).afiche.showAfiche();
firstTime = false;
}
}
Now, the file loads, because the output console shows everything I told the AS2 file ("verano.swf") to trace, but it doesn't display nevertheless.
The full code as follows:
package
{
import flash.display.MovieClip;
import flash.net.FileFilter;
import flash.net.FileReference;
import flash.net.URLRequest;
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.external.*;
import flash.net.URLLoaderDataFormat;
import flash.net.URLLoader;
import flash.display.Loader;
import flash.events.*;
import gs.TweenMax;
import gs.plugins.*;
public class Tabu extends MovieClip
{
public var currentMovie:MovieClip;
public var currentMovieName:String;
var firstTime:Boolean = true;
function Tabu()
{
trace("inicializando pagina");
ExternalInterface.addCallback("loadSeccion", callMe);
}
public function callMe(name:String) {
trace("callme");
this.x = -200;
}
function loadHome()
{
startLoad("home_1_v2.swf");
var ldr:Loader = new Loader();
var rand:String = Math.floor(Math.random() * 100000000) + "?";
var spot_url:String = "http://ad.doubleclick.net/activity;src=2951116;type=lanza404;cat=inte760;ord=1;num=";
var tag_url:String = spot_url + rand;
var urlReq:URLRequest = new URLRequest(tag_url);
ldr.load(urlReq);
}
function startLoad(url:String)
{
if (currentMovieName != url)
{
currentMovieName = url;
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest(currentMovieName);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
try {
(mLoader.content as Object).removed();
}catch (err:Error)
{
}
}
function onCompleteHandler(loadEvent:Event)
{
currentMovie = loadEvent.currentTarget.content as MovieClip;
addChild(currentMovie);
if (firstTime)
{
(root as MovieClip).afiche.showAfiche();
firstTime = false;
}
}
public function setPage(e:MouseEvent)
{
if (e.target.name == "btn_1")
changePage("campana.swf");
if (e.target.name == "btn_2")
changePage("toma_tabu.swf");
else if (e.target.name == "btn_3")
changePage("verano.swf"); //This is the one! AS2 file!
else if (e.target.name == "btn_4")
changePage("manda_tu_tabu.swf");
else if (e.target.name == "btn_0")
changePage("home_1_v2.swf");
}
public function setPageString(s:String)
{
changePage(s);
}
function changePage(newPage:String)
{
if (currentMovieName != newPage)
{
TweenMax.to(currentMovie, 1, { frame:1, onComplete:finishUnload, onCompleteParams:[newPage] } );
}
}
function finishUnload(newPage:String)
{
//removeChild(currentMovie);
startLoad(newPage);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
}
}