Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-21-2010, 03:21 PM   #1
stofferd2
Registered User
 
Join Date: Jul 2010
Posts: 2
Default Controlling the timeline of externally loaded SWFs

I am working on a flash file that will load external swf animations. At the moment I can successfully load a number of flash animations from an xml file called swflist.xml.

Previously we had a problem where flash would reload each swf each time you clicked. This crashed our website so as a solution we decided to use setChildIndex to just bring the desired swf to the top. This works great but because we dont load each swf afresh, as you click through the swfs they are halfway through playing.

-I need the selected swf to go to back to its first frame when the user selects it.
-I also need to detect the swf animation length so I can set it to automatically bring the next animation to the top (using childIndex)

So my questions are:
How can you control the timeline of an external swf?
I used goToAndPlay(0) which did nothing so then I used a trace currentFrame and totalFrames which told me that each swf had only one frame.
Why can flash not determine how many frames the swf has?
Does anyone know of any good tutorials on loading and controlling external swfs?

Any help much appreciated!

P.S. This is a mix of my code and a web developer's so there are differences in styles. For example he is king of for loops...

ActionScript Code:
import flash.display.*; import flash.net.URLRequest; import flash.display.Sprite; var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE,xmlloaded); var xml:XML = new XML(); var amountofvid:Number=0; var currentvideo:Number=0; var swfs = new Array(); btn1.addEventListener(MouseEvent.CLICK,nextvid); btn2.addEventListener(MouseEvent.CLICK,prevvid); vid1.addEventListener(MouseEvent.CLICK,firstvid); vid2.addEventListener(MouseEvent.CLICK,secondvid); vid3.addEventListener(MouseEvent.CLICK,thirdvid); vid4.addEventListener(MouseEvent.CLICK,fourthvid); vid5.addEventListener(MouseEvent.CLICK,fifthvid); vid6.addEventListener(MouseEvent.CLICK,sixthvid); function xmlloaded(e:Event) {     xml=XML(e.currentTarget.data);     amountofvid=xml.video.length()-1;     trace("the number of videos is",amountofvid);     trace("the number of children is",numChildren);         for (var i in xml.video.@src) {         trace("Hit: " + xml.video.@src[i]);         var reqURL:URLRequest = new URLRequest(xml.video.@src[i]);         var loader:Loader = new Loader();         swfs[i] = new MovieClip();         loader.load(reqURL);         swfs[i].addChild(loader);         addChild(swfs[i]);     } } //  increases current video number i.e. chooses the next video function nextvid(e:Event) {     currentvideo++;     changevid(); } //  decreases the current video number i.e. chooses previous video function prevvid(e:Event) {     currentvideo--;     changevid(); } //D   These choose specific video numbers function firstvid(e:Event) {     currentvideo=0;     changevid();      } function secondvid(e:Event) {     currentvideo=1;     changevid(); } function thirdvid(e:Event) {     currentvideo=2;     changevid(); } function fourthvid(e:Event) {     currentvideo=3;     changevid(); } function fifthvid(e:Event) {     currentvideo=4;     changevid(); } function sixthvid(e:Event) {     currentvideo=5;     changevid(); } function changevid():void {     var cv:Number=Math.abs(currentvideo);     if (cv>amountofvid) {         currentvideo=cv=0;     }     if (currentvideo<0) {         currentvideo=cv=amountofvid;     }     t_txt.text=xml.video.@title[cv];     setChildIndex(swfs[cv], numChildren-1); } link.addEventListener(MouseEvent.MOUSE_UP, gotoURL); function gotoURL(e:MouseEvent):void {     var cv:Number=Math.abs(currentvideo);     var url:URLRequest=new URLRequest(xml.video.@link[cv]);     navigateToURL(url, "_parent"); } loader.load(new URLRequest('swflist.xml'));
stofferd2 is offline   Reply With Quote
Old 07-21-2010, 06:00 PM   #2
Cota
Super Moderator
 
Cota's Avatar
 
Join Date: Jul 2001
Location: NYC
Posts: 10,175
Default

Give this a read.
http://stackoverflow.com/questions/5...lly-loaded-swf

External SWF's dont work like they used to...
__________________
Color Wars™ | (kul′ər wôrs) n. - Open conflict between factions. www.theColorWars.com

cota - www.chadworkman.com | http://shavedplatypus.com
occupation: designer | flash developer | server-side developer (php, asp, mssql, mysql)
Cota is offline   Reply With Quote
Old 07-26-2010, 03:07 PM   #3
stofferd2
Registered User
 
Join Date: Jul 2010
Posts: 2
Thumbs up Resolved

I worked out how to control the timeline. I used:

ActionScript Code:
MovieClip(loaders[cv].content).gotoAndPlay(0);

I created an array of loaders so that I could use .content on each one.
ActionScript Code:
var loaders = new Array(); ... loaders[i] = new Loader();

Here is my complete code:
ActionScript Code:
import flash.display.*; import flash.net.URLRequest; import flash.display.Sprite; var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE,xmlloaded); var xml:XML = new XML(); var amountofvid:Number=0; var currentvideo:Number=0; var swfs = new Array(); var loaders = new Array(); btn1.addEventListener(MouseEvent.CLICK,nextvid); btn2.addEventListener(MouseEvent.CLICK,prevvid); vid1.addEventListener(MouseEvent.CLICK,firstvid); vid2.addEventListener(MouseEvent.CLICK,secondvid); vid3.addEventListener(MouseEvent.CLICK,thirdvid); vid4.addEventListener(MouseEvent.CLICK,fourthvid); vid5.addEventListener(MouseEvent.CLICK,fifthvid); vid6.addEventListener(MouseEvent.CLICK,sixthvid); function xmlloaded(e:Event) {     xml=XML(e.currentTarget.data);     amountofvid=xml.video.length()-1;     trace("the number of videos is",amountofvid);     trace("the number of children is",numChildren);         for (var i in xml.video.@src) {         trace("Hit: " + xml.video.@src[i]);         var reqURL:URLRequest = new URLRequest(xml.video.@src[i]);         //var loader:Loader = new Loader();         loaders[i] = new Loader();         swfs[i] = new MovieClip();         loaders[i].load(reqURL);         swfs[i].addChild(loaders[i]);         contain.addChild(swfs[i]);     } } //   increases current video number i.e. chooses the next video function nextvid(e:Event) {     currentvideo++;     changevid(); } //   decreases the current video number i.e. chooses previous video function prevvid(e:Event) {     currentvideo--;     changevid(); } //   These choose specific video numbers function firstvid(e:Event) {     currentvideo=0;     changevid();      } function secondvid(e:Event) {     currentvideo=1;     changevid(); } function thirdvid(e:Event) {     currentvideo=2;     changevid(); } function fourthvid(e:Event) {     currentvideo=3;     changevid(); } function fifthvid(e:Event) {     currentvideo=4;     changevid(); } function sixthvid(e:Event) {     currentvideo=5;     changevid(); } function changevid():void {     var cv:Number=Math.abs(currentvideo);     if (cv>amountofvid) {         currentvideo=cv=0;     }     if (currentvideo<0) {         currentvideo=cv=amountofvid;     }     t_txt.text=xml.video.@title[cv];     contain.setChildIndex(swfs[cv], contain.numChildren-1);         MovieClip(loaders[cv].content).gotoAndPlay(0);         } link.addEventListener(MouseEvent.MOUSE_UP, gotoURL); function gotoURL(e:MouseEvent):void {     var cv:Number=Math.abs(currentvideo);     var url:URLRequest=new URLRequest(xml.video.@link[cv]);     navigateToURL(url, "_parent"); } loader.load(new URLRequest('swflist.xml'));
stofferd2 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:34 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.