Critique My Code

Hey all,

I’ve come up with some code(with help from forums) that allows me control elements in an external.swf through buttons in my main.swf and vice versa.

Of course, different external.swfs are going to have differing movie clips.

Currently, I’m controlling the elements of multiple external.swfs using only two functions(one for opening and another for closing an external.swf) This is possible by using “if statements” to see if the elements of a given swf have been loaded.

I guess what I’m asking: Is there a better way to write this code? I’m sure there is (I’m not a programmer)

Here is my code for loading external swfs:

var _swfContainer:Loader = new Loader()

var _url1:URLRequest = new URLRequest("loadBio.swf")
var _url2:URLRequest = new URLRequest("loadMedia.swf")
var _url3:URLRequest = new URLRequest("loadBlogs.swf")

var _externalMovie:MovieClip;

//Start loading and add the loader to the stage

stage.addChild(_swfContainer);
_swfContainer.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, finishedLoading);


// This is done after the swf is loaded
function finishedLoading (e:Event)
{
	
    _externalMovie = MovieClip(_swfContainer.content);
	
}

Here is the function I use to control the elements of all the external.swfs (animations to open and close the .swfs")

function activateSelectedExternalSWFelements(e:MouseEvent):void{
	
	///////// ACCESSING AN EXTERNAL SWF'S MOVIE CLIP///////////////////////////////////////////////////////////////
	_swfContainer.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, finishedLoading);//necessary to see if 
	//ext swf has loaded before accessing movie clip in ext swf
	
	function finishedLoading (e:Event){
		//now that the external SWF has finished loading, we can manipulate it's elements
		//The following items are present on each external SWF/////
		_externalMovie.pageTitle.alpha=0;
		_externalMovie.btnBack.alpha=0;
		_externalMovie.pageFlipOut.visible=false;
		_externalMovie.pageFlipIn.alpha=0;
		_externalMovie.btnBack.buttonMode=true;
	
		Tweener.addTween(_externalMovie.pageTitle, {alpha:1, time:2, delay:1, transition:"easeInOutExpo"});
		Tweener.addTween(_externalMovie.pageFlipIn, {alpha:0.5, time:2, delay:0, transition:"easeInOutExpo"});
		Tweener.addTween(_externalMovie.btnBack, {alpha:1, time:2, delay:1, transition:"easeInOutExpo"});
		_externalMovie.btnBack.addEventListener(MouseEvent.CLICK, navAnimIn);
		_externalMovie.btnBack.addEventListener(MouseEvent.CLICK, closeCurrentPage);
		_externalMovie.pageFlipIn.gotoAndPlay(2);
	/// end items present on each external SWF /////////////////////////
	
	//Settings specific to loadBio.swf//////
			//initial loadBio.swf settings///
		if (_externalMovie.bioText != null){
			_externalMovie.bioText.alpha=0;
			_externalMovie.bioVideo.alpha=0;
			_externalMovie.bioPhotos.alpha=0;
			
			//animate loadBio.swf elements in///
			Tweener.addTween(_externalMovie.bioText, {alpha:1, time:1, delay:2, transition:"easeInOutExpo"});
			Tweener.addTween(_externalMovie.bioVideo, {alpha:1, time:1, delay:2, transition:"easeInOutExpo"});
			Tweener.addTween(_externalMovie.bioPhotos, {alpha:1, time:1, delay:2, transition:"easeInOutExpo"});
		}
		
	//Settings specific to loadMedia.swf//////
		//initial loadMedia.swf settings///
	if (_externalMovie.mediaText != null){
			_externalMovie.mediaText.alpha=0;
			_externalMovie.mediaBox.alpha=0;
			
			//animate loadBio.swf elements in///
			Tweener.addTween(_externalMovie.mediaText, {alpha:1, time:1, delay:2, transition:"easeInOutExpo"});
			Tweener.addTween(_externalMovie.mediaBox, {alpha:1, time:1, delay:2, transition:"easeInOutExpo"});
		}
		
	//Settings specific to loadBlogs.swf//////
		//initial loadBlogs.swf settings///
	if (_externalMovie.blogsText != null){
			_externalMovie.blogsText.alpha=0;
			_externalMovie.blogsBox.alpha=0;
			
			//animate loadBlogs.swf elements in///
			Tweener.addTween(_externalMovie.blogsText, {alpha:1, time:1, delay:2, transition:"easeInOutExpo"});
			Tweener.addTween(_externalMovie.blogsBox, {alpha:1, time:1, delay:2, transition:"easeInOutExpo"});
		}
		

	}
	
}


function closeCurrentPage(event:MouseEvent){
	// These elements are present on each of the external .swfs
	Tweener.addTween(_externalMovie.pageTitle, {alpha:0, time:1, delay:0, transition:"easeInOutExpo"});
	Tweener.addTween(_externalMovie.btnBack, {alpha:0, time:1, delay:0, transition:"easeInOutExpo"});
	_externalMovie.pageFlipIn.visible=false;
	_externalMovie.pageFlipOut.visible=true;
	_externalMovie.pageFlipOut.alpha=0.5;
	_externalMovie.pageFlipOut.gotoAndPlay(2);
	Tweener.addTween(_externalMovie.pageFlipOut, {alpha:0, time:1, delay:1, transition:"easeInOutExpo"});
	
	//These commands are for elements which may be present on only certain external swfs
	//therefore, a check ("if" statement) needs to be done to see if the elements are on the present swf
	
	//Close out elements specific to loadBio.swf/////
	if(_externalMovie.bioText != null){
		Tweener.addTween(_externalMovie.bioText, {y:280, alpha:0, time:1, delay:0, transition:"easeInOutExpo"});
		Tweener.addTween(_externalMovie.bioVideo, {alpha:0, time:1, delay:0, transition:"easeInOutExpo"});
		Tweener.addTween(_externalMovie.bioVideo, {visible:false, delay:2, transition:"easeInOutExpo"});//must go to visible to avoid overlaying nav
		Tweener.addTween(_externalMovie.bioPhotos, {alpha:0, time:1, delay:0, transition:"easeInOutExpo"});
		Tweener.addTween(_externalMovie.bioPhotos, {visible:false, delay:2, transition:"easeInOutExpo"});//must go to visible to avoid overlaying nav
	}
	
	//Close out elements specific to loadMedia.swf/////
	if(_externalMovie.mediaText != null){
		Tweener.addTween(_externalMovie.mediaText, {y:280, alpha:0, time:1, delay:0, transition:"easeInOutExpo"});
		Tweener.addTween(_externalMovie.mediaBox, {alpha:0, time:1, delay:0, transition:"easeInOutExpo"});
		Tweener.addTween(_externalMovie.mediaBox, {visible:false, delay:2, transition:"easeInOutExpo"});//must go to visible to avoid overlaying nav
	}
	
	//Close out elements specific to loadBlogs.swf/////
	if(_externalMovie.blogsText != null){
		Tweener.addTween(_externalMovie.blogsText, {y:280, alpha:0, time:1, delay:0, transition:"easeInOutExpo"});
		Tweener.addTween(_externalMovie.blogsBox, {alpha:0, time:1, delay:0, transition:"easeInOutExpo"});
		Tweener.addTween(_externalMovie.blogsBox, {visible:false, delay:2, transition:"easeInOutExpo"});//must go to visible to avoid overlaying nav
	}
}

All this code is within the main.swf. No code exists in any of the external.swfs (I like the idea of the code only being in main.swf)

Notice that there is code for elements that are the same on every external.swf: Title, btnBack, PageFlipIn, PageFlipOut.

There is also a section that controls elements that are specific to a particular .swf

Right now, I use an “If Statement” to check if one of the elements in an external swf is loaded. If true, then I can manipulate elements specific to that particular .swf

What I was wanting to was use the name of the particular .swf in the “If Statement” instead of targeting a specific movie clip in that external.swf.

This works perfectly…but I think I maybe overcomplicating things?

Any ideas for a rewrite would be appreciated…sorry for the in-depth explanation (it’s wordy, I know) just trying to be clear.

Thanks
Damon