FORUMS: list search recent posts

button appearing after .swf finishes playing?

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Desiree Damon
button appearing after .swf finishes playing?
on Jul 23, 2009 at 8:27:42 pm

I'm working on assembling a webcast with many smaller parts. Each part consists of an already created .swf file. I can get the .swf to load, but I'm having problems figuring out how to make the button work. It needs to appear only AFTER the .swf finishes playing, and then take them to the next chapter.

Does anyone have any suggestions?
Thank you, in advance!


Here's my code:

stop();

btnBegin.visible=false;

var sRequest:URLRequest = new URLRequest("intro.swf");
var swfLoader:Loader = new Loader();
swfLoader.load(sRequest);
this.addChild(swfLoader);

swfLoader.addEventListener(Event.COMPLETE, revealButton);
function revealButton (evtobj:Event) :void{

btnBegin.visible=true;

}

btnBegin.addEventListener (MouseEvent.CLICK, goNext);
function goNext (evtObj:MouseEvent) :void{

gotoAndPlay ("chap1");

}


Return to posts index

demetri tashie
Re: button appearing after .swf finishes playing?
on Jul 25, 2009 at 5:21:22 pm

desiree,

here is one way to approach this. you have to always keep in mind that a loaded SWF is seen by the main SWF as a Display Object, and not a MovieClip until it is declared as such ( in my example i used "ExtSwfContainer" as the name of the loaded swf). Also, from your code above, "COMPLETE" just says that the swf has fully loaded, NOT that it has played out.
you'll see that some of the code is re-aranged from the way you had it, so that everything is referenced correctly.

i did make test example of this new code, so i know that it will work for you. hopefully it all makes sense to you. if not, just ask !


stop();

btnBegin.visible=false;

var ExtSwfContainer:MovieClip;

var sRequest:URLRequest = new URLRequest("intro.swf");
var swfLoader:Loader = new Loader();

swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompletedHandler);
function loaderCompletedHandler(evt:Event):void { ExtSwfContainer = swfLoader.content as MovieClip; addChild(ExtSwfContainer);

swfLoader.addEventListener(Event.ENTER_FRAME, revealButton);
function revealButton (evt:Event) :void{

if(ExtSwfContainer.currentFrame==ExtSwfContainer.totalFrames){trace("hello");
btnBegin.visible=true; swfLoader.removeEventListener(Event.ENTER_FRAME, revealButton);}
}
}

swfLoader.load(sRequest);
addChild(swfLoader);

btnBegin.addEventListener (MouseEvent.CLICK, goNext);
function goNext (evtObj:MouseEvent) :void{
gotoAndPlay ("chap1");
}





Return to posts index

Desiree Damon
Re: button appearing after .swf finishes playing?
on Jul 27, 2009 at 2:18:48 pm

Thanks so much for your help. But I tried out your code, and I still seem to be having problems...

The button is still visible from the moment the content loads, not after the swf, which is now defined as a movie clip, finishes playing.


And when I copy/paste the code into the next frame (for my chapter 1) changing the name of the swf and making sure the function names aren't duplicated, I get these errors and I don't know why...

1151: A conflict exists with definition sRequest in namespace internal.
1151: A conflict exists with definition swfLoader in namespace internal.


Return to posts index


demetri tashie
Re: button appearing after .swf finishes playing?
on Jul 27, 2009 at 8:21:51 pm

sorry you are still having problems.

i re-tested the code again, several times, each time changing variables, and it works under all the new conditions.

the ENTER_FRAME pretty much clearly tells the button to be visible only once reaching it's last frame.
might you have a single frame SWF? maybe it is a single framed swf with nested movieclips ??

there is obviously now more going on than you first gave code for. it will be more productive if you want to post your file so we can look at it in it's entiretly.

also- do you have code in your externally loaded swfs that could be interfereing ?


Return to posts index

Desiree Damon
Re: button appearing after .swf finishes playing?
on Aug 4, 2009 at 8:27:30 pm

Sorry for not replying back sooner, I had to complete another rush job first...

Yes. each one is a single frame .swf. And each .swf does contain a movie clip, loaded within the flvplayback component. I have all the associated .flv files in the same folder as the .swfs, so I know that's in good working order. None of the swfs have additional actionscript.



Return to posts index

demetri tashie
Re: button appearing after .swf finishes playing?
on Aug 5, 2009 at 1:12:31 pm

ok, i see now that you have revealed more layers of complexity that of course have to be taken into consideration.
if the loaded SWF is just a 1 frame SWF , then of course the button shows up immediately,as the code was telling it to reveal the button on the SWF's last frame - which of course is equal to its first frame, so it would appear immediately.

so, i think you are trying to say NOT when the SWF has finished playing ( cause it already has after 1 frame ) but when a FLV component in that SWF has reached the last frame of the video ?

that is a different case - same logic, just diffeent code. you need to have the FLV Component that you used listen for COMPLETE, and then it can trigger the function to 'reveal' the button.

you would need to do something like this ( i am not anywhere where i can test this code, so it might need some adjusting)
instead of this older code:
swfLoader.addEventListener(Event.ENTER_FRAME, revealButton);
function revealButton (evt:Event) :void{

if(ExtSwfContainer.currentFrame==ExtSwfContainer.totalFrames){trace("hello");
btnBegin.visible=true; swfLoader.removeEventListener(Event.ENTER_FRAME, revealButton);}
}
}


you would need something like this:

import fl.video.VideoEvent;

swfLoader.FLVPlayerComponentInstanceName.addEventListener(VideoEvent.COMPLETE, revealButton);
function revealButton (evt:Event) :void{
trace("hello");
btnBegin.visible=true;
swfLoader.FLVPlayerComponentInstanceName.removeEventListener(Event.ENTER_FRAME, revealButton);}
}


and now of course pay attention to add this code only after there is swfLoader.FLVPlayerComponentInstanceName on the stage/display list

hope that ll makes sense.







Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]