开发者

smooth transitions between external swfs.

开发者 https://www.devze.com 2023-03-30 15:11 出处:网络
I\'m trying to get back into flash. trying to write some code here but...well, let me show you. what I want and currently have is a main swf that loads in assets based on buttons pressed. I have 3 ex

I'm trying to get back into flash. trying to write some code here but...well, let me show you.

what I want and currently have is a main swf that loads in assets based on buttons pressed. I have 3 external SWFs (for the sake of this example, lets call the initial loaded swf "indexExt.swf", file two" f02.swf" and file three, " f03.swf") and in each of them,there's one l开发者_如何转开发ayer that goes from frame 1 to frame 10.

On frame 1, there's an "intro" label, on frame 5, an "outro" label, and on frame 10, an " end" label.

indexExt.swf is loaded on initial load of the main swf.

as for my buttons, I gave my buttons on the main swf stage, instance names that are the same name as the external swfs so that with this line event.target.name + ".swf" I can call em in without having to re-write code for every button etc..

the button code im using for normal importing is this below:

f01.addEventListener(MouseEvent.CLICK,btnclick);
f02.addEventListener(MouseEvent.CLICK,btnclick);


function btnclick(event:MouseEvent):void{

removeChild(loader);

var newSwfRequest:URLRequest = new URLRequest( event.target.name + ".swf");

loader.load(newSwfRequest);
loader.x = Xpos;
loader.y = Ypos;
addChild(loader);

}

now the problem I'm having is that I don't know how to target whatever is clicked / imported /loaded in.

Overall, what I want to do is, rework the button code above, into something like so below:

// non code but you get the idea //


on press, if something is loaded, go to and play its "outro" frame label.
if "end frame label" load in event.target.name + ".swf"

i hope its not confusing. essentially what i want is that on button press, that whatever movie is loaded, play the outro label and IF and when, the "end" label is hit, load up whatever the user clicked on.

I think this is a sound way of doing it but, I tend to sometimes go for the hardest method. I'm no where near a pro but any hints /tips/code etc, I'll gladly accept.


You need to add a listener to your loader object for a complete event. That will give you the reference you're looking for. Then you can tell that object, if set, to go to the desired frame when your button is clicked.

var loaded:Object;

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoaded);

function handleLoaded(e:Event):void {
  loaded = e.target.content;
}

btn.addEventListener(MouseEvent.CLICK, handleClick);

function handleClick(e:MouseEvent):void {
  if (loaded) {
    loaded.gotoAndPlay("outro");
  }

  //load new swf
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号