Jump to content
Search Community

Play .swf after tweening is done

Harvid test
Moderator Tag

Recommended Posts

hey

I can not figure out what I'm doing wrong

i just want the loaded swf to play after tweening is don

 

 

TweenLite.to(loader2, 2.5 , {alpha:1, onComplete:play});

 

there is a stop at frame 1 in the .swf

 

 

pleas help me i am really trying to learn, As you can see, not very nice looking code... :-s

 

sorry for my english

 

var ShowArray:Array = [g1, g2, g3, g4 ,g5, g6, g7, g8];
///////////////////////////////////////////////////////////////////////////////



TweenLite.to(preloader, 0 , {alpha:0});

g1.addEventListener(MouseEvent.CLICK,Showclick)
g2.addEventListener(MouseEvent.CLICK,Showclick)
g3.addEventListener(MouseEvent.CLICK,Showclick)
g4.addEventListener(MouseEvent.CLICK,Showclick)
g5.addEventListener(MouseEvent.CLICK,Showclick)
g6.addEventListener(MouseEvent.CLICK,Showclick)
g7.addEventListener(MouseEvent.CLICK,Showclick)
g8.addEventListener(MouseEvent.CLICK,Showclick)






var loader1:Loader = new Loader();
var loader2:Loader = new Loader();
var switcher = 0;

function Showclick(event:MouseEvent):void{
if (switcher == 0)
   {
loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded1); 
    //loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress2); 
   loader1.load(new URLRequest("test/"+event.target.name+".swf"));
   loader1.x = 0;
   loader1.y = 86;
switcher = 1;
trace("første")
   }
else
{
loader2.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded2); 
    //loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgress2); 
   loader2.load(new URLRequest("test/"+event.target.name+".swf"));
   loader2.x = 0;
   loader2.y = 86;
switcher = 0;
trace("anden")
}
}



///////////////////////////////////// loader 1 /////////////////////////////////////
function loadMainx1():void {
TweenLite.from(preloader.preloadText, 0.5 , {alpha:0});
} 
/*---------------------------------------------------------------------------------*/ 
function onProgress1(e:ProgressEvent):void 
{ 
   TweenLite.to(preloader, 0.5 , {alpha:1, onComplete:loadMainx1});
   TweenLite.to(loader2, 1.5 , {alpha:0});
   var percentage:Number = e.bytesLoaded / e.bytesTotal; 
   preloader.preloadText.text = Math.ceil(percentage * 100).toString() + "%"; 
} 
/*---------------------------------------------------------------------------------*/ 

function onLoaded1(e:Event):void 
{ 
   TweenLite.to(preloader, 1 , {alpha:0, onComplete:loadMain1}); 
TweenLite.to(loader2,  1 , {alpha:0});
} 
/*---------------------------------------------------------------------------------*/ 
function loadMain1():void 
{  
   TweenLite.to(loader1, 0 , {alpha:0}); 
   addChild(loader1); 
   TweenLite.to(loader1, 2.5 , {alpha:1, onComplete:play()});
   removeChild(loader2); 
} 



///////////////////////////////////// loader 2 /////////////////////////////////////
function loadMainx2():void {
TweenLite.from(preloader.preloadText, 0.5 , {alpha:0});
} 
/*---------------------------------------------------------------------------------*/ 
function onProgress2(e:ProgressEvent):void 
{ 
   TweenLite.to(preloader, 0.5 , {alpha:1, onComplete:loadMainx2});
   TweenLite.to(loader1, 1.5 , {alpha:0});
   var percentage:Number = e.bytesLoaded / e.bytesTotal; 
   preloader.preloadText.text = Math.ceil(percentage * 100).toString() + "%"; 
} 
/*---------------------------------------------------------------------------------*/ 

function onLoaded2(e:Event):void 
{ 
   TweenLite.to(preloader, 1 , {alpha:0, onComplete:loadMain2}); 
TweenLite.to(loader1,  1 , {alpha:0});
} 
/*---------------------------------------------------------------------------------*/ 
function loadMain2():void 
{ 
   TweenLite.to(loader2, 0 , {alpha:0}); 
   addChild(loader2); 
   TweenLite.to(loader2, 2.5 , {alpha:1, onComplete:play});
removeChild(loader1); 
} 

Link to comment
Share on other sites

I do not understand why it does not work

I get this error message

 

Scene 1, Layer 'action', Frame 1, Line 86 1119: Access of possibly undefined property play through a reference with static type flash.display:Loader.

Scene 1, Layer 'action', Frame 1, Line 116 1119: Access of possibly undefined property play through a reference with static type flash.display:Loader.

 

what am I not doing right ?

Link to comment
Share on other sites

Oh, it's because you're trying to call play() on a Loader instance - there is no such method. If you want to play the subloaded content (assuming it's a MovieClip), you'd need to call play() on the Loader's content and cast it as a MovieClip like:

 

TweenLite.to(loader1, 2.5 , {alpha:1, onComplete:MovieClip(loader1.content).play});

 

Of course you can only reference the content AFTER the Loader has completed loading the swf.

 

However, beware that there's a bug in Adobe's Loader class that can cause "content" to be invalid. To avoid this (and many other bugs), I'd recommend using LoaderMax. In that case, you'd play() the rawContent.

 

var loader:SWFLoader = new SWFLoader("child.swf", {onComplete:completeHandler, container:this});
loader.load();

function completeHandler(event:LoaderEvent):void {
   TweenLite.to(loader, 2.5 , {alpha:1, onComplete:loader.rawContent.play});
}

 

See http://www.LoaderMax.com to get LoaderMax. You probably already have it if you're using the latest version of the GreenSock tweening classes (it's in the zip).

Link to comment
Share on other sites

Hey

I can not get it to work with LoaderMax.

for some reason I can not get it to wait for the onComplete, it immediately start to play ?

 

queue1.append( new SWFLoader("test/"+event.target.name+".swf", {name:"mainClip1", alpha:0, container:this, y:86, autoPlay:false}))

 

TweenLite.to(image1, 1.5 , {alpha:1, onComplete:image1.rawContent.play});

 

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;
import flash.display.StageDisplayState;


var ShowArray:Array = [g1, g2, g3, g4 ,g5, g6, g7, g8];
////////////////////////////////////////////////////////////
g1.addEventListener(MouseEvent.CLICK,Showclick)
g2.addEventListener(MouseEvent.CLICK,Showclick)
g3.addEventListener(MouseEvent.CLICK,Showclick)
g4.addEventListener(MouseEvent.CLICK,Showclick)
g5.addEventListener(MouseEvent.CLICK,Showclick)
g6.addEventListener(MouseEvent.CLICK,Showclick)
g7.addEventListener(MouseEvent.CLICK,Showclick)
g8.addEventListener(MouseEvent.CLICK,Showclick)
////////////////////////////////////////////////////////////
var switcher = 0; 
var switcher2 = 0;
var queue1:LoaderMax = new LoaderMax({name:"mainQueue1", onProgress:progressHandler1, onComplete:completeHandler1/*, onError:errorHandler*/});
var queue2:LoaderMax = new LoaderMax({name:"mainQueue2", onProgress:progressHandler2, onComplete:completeHandler2/*, onError:errorHandler*/});
TweenLite.to(preloadText, 0 , {alpha:0});
function Showclick(event:MouseEvent):void{
trace(event.target.name + " load");
  if (switcher == 0){ 
   queue1.empty(true, true);
   queue1.append( new SWFLoader("test/"+event.target.name+".swf", {name:"mainClip1", alpha:0, container:this, y:86, autoPlay:false}));
   queue1.load();
switcher = 1;
trace("første")
   }
else
{
   queue2.empty(true, true);
queue2.append( new SWFLoader("test/"+event.target.name+".swf", {name:"mainClip2", alpha:0, container:this, y:86, autoPlay:false}));
   queue2.load();
switcher = 0;
trace("anden")
}
}
////////////////loader queue 1//////////////////////////////////////////

function progressHandler1(event:LoaderEvent):void { 
preloadText.text = ("Loading " + Math.round(event.target.progress*100).toString() + "%");
TweenLite.to(preloadText, 1.0 , {alpha:1});
 if (switcher2 == 1){
   //clip exists 
var image2:ContentDisplay = LoaderMax.getContent("mainClip2");

TweenLite.to(image2, 1.5 , {alpha:0});
}
}
/*--------------------------------------------------------------*/
function completeHandler1(event:LoaderEvent):void 
{  
TweenLite.to(preloadText,  1.5 , {alpha:0});
   if (switcher2 == 1){
var image2:ContentDisplay = LoaderMax.getContent("mainClip2");
TweenLite.to(image2, 0.5 , {alpha:0, onComplete:completeHandler1OK})
   }
else
{ 
completeHandler1OK()
}} 

/*--------------------------------------------------------------*/
function completeHandler1OK():void 
{
 var image1:ContentDisplay = LoaderMax.getContent("mainClip1");
 TweenLite.to(image1, 1.5 , {alpha:1, onComplete:image1.rawContent.play()});
queue2.empty(true, true);
}


/////////////////loader queue 2//////////////////////////////////////////////
function progressHandler2(event:LoaderEvent):void { 
preloadText.text = ("Loading " + Math.round(event.target.progress*100).toString() + "%");
TweenLite.to(preloadText, 1.0 , {alpha:1});
var image1:ContentDisplay = LoaderMax.getContent("mainClip1");
TweenLite.to(image1, 1.5 , {alpha:0});
}
/*--------------------------------------------------------------*/
function completeHandler2(event:LoaderEvent):void 
{  
TweenLite.to(preloadText,  1.5 , {alpha:0});
var image1:ContentDisplay = LoaderMax.getContent("mainClip1");
TweenLite.to(image1, 0.5 , {alpha:0, onComplete:completeHandler2OK})

} 

/*--------------------------------------------------------------*/
function completeHandler2OK():void 
{
 var image2:ContentDisplay = LoaderMax.getContent("mainClip2");
 TweenLite.to(image2, 1.5 , {alpha:1, onComplete:image2.rawContent.play});
 switcher2 = 1;
queue1.empty(true, true);
}
////////////////////////////////////////////////////////////

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...