I have such a code:
var a:Array = new Array(s4_1_arch,btn_back);
var p:MovieClip = new MovieClip();
p = MovieClip(parent);
var url:URLRequest;
var myLoader:Loader = new Loader();
var loaded:Boolean;
function samClick(e:MouseEvent):void
{
trace(e.target.name);
switch (e.target)
{
case s4_1_arch :
loaded = true;
if (loaded)
{
url = new URLRequest("gallery.swf");
stage.addChild(myLoader);
myLoader.load(url);
var loaderTween:Tween = new Tween(myLoader,"alpha",Strong.easeIn,0,1,1,true);
s4_1_arch.removeEventListener(MouseEvent.CLICK, samClick);
}
break;
case btn_back :
if (loaded)
{
myLoader.unloadAndStop();
stage.removeChild(myLoader);
loaded = false;
trace(myLoader.stage);
s4_1_arch.addEventListener(MouseEvent.CLICK, samClick);
var btn1back:Tween = new Tween(p.btn1,"y",Strong.easeOut,p.btn1.y,-150,1,true);
var btn2back:Tween = new Tween(p.btn2,"y",Strong.easeOut,p.btn2.y,-110,1,true);
var btn3back:Tween = new Tween(p.btn3,"y",Strong.easeOut,p.btn3.y,-70,1,true);
var btn4back:Tween = new Tween(p.btn4,"y",Strong.easeOut,p.btn4.y,-30,1,true);
var btn5back:Tween = new Tween(p.btn5,"y",Strong.easeOut,p.btn5.y,10,1,true);
var btn6back:Tween = new Tween(p.btn6,"y",Strong.easeOut,p.btn6.y,50,1,true);
var btn7back:Tween = new Tween(p.btn7,"y",Strong.easeOut,p.btn7.y,90,1,true);
var btn8back:Tween = new Tween(p.btn8,"y",Strong.easeOut,p.btn8.y,130,1,true);
var submenu4:Tween = new Tween(p.btn4_sub,"x",Strong.easeOut,p.btn4_sub.x,270,1,true);
var submenu4up:Tween = new Tween(p.btn4_sub,"y",Strong.easeOut,p.btn4_sub.y,0,1,true);
submenu4up.addEventListener(TweenEvent.MOTION_FINISH, doSomeStuff);
}
for (var i:Number = 0; i < 2; i++)
{
a*.addEventListener(MouseEvent.CLICK, samClick);
}
My problem is that the method unloadAndStop
- stops all my tweens
.
I tried to use the method unload
, and all works, but when i click again on the button s4_1_arch
everything works fine, but i get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Function/<anonymous>()
I also tried to use this code:
if (loaded)
{
myLoader.unloadAndStop();
stage.removeChild(myLoader);
loaded = false;
trace(myLoader.stage);
}
else
{
s4_1_arch.addEventListener(MouseEvent.CLICK, samClick);
var btn1back:Tween = new Tween(p.btn1,"y",Strong.easeOut,p.btn1.y,-150,1,true);
//all my Tweens
}
In this case the tweens works when i click the button btn_back the second time.
I need to unload and play tweens at once without output errors.
Can anyone help?