Jump to content

createMovieClip()- control from a button


dnainby

Recommended Posts

i'm currently using the createMovieClip() function. I have dynamically created Movie Clip and loaded a file into it and it works fine. All i need to do is control the Movie Clip from a seperate button to say, stop(), gotoAndStop(), play() etc etc...The code i have used is below. I can't seem to control the Movie Clip from the button at the moment and i don't want to have to put the button function inside the loadListener (it works in there!).Any suggestions would be greatly recieved. MTIA

//init variablesmovieToLoad = "Media/SWF/anim.swf";createMovieClip();step_but.onRelease=function() {	trace("button pressed");	contentHolder.stop();};//CREATE MOVIE CLIP TO HOLD IMAGEfunction createMovieClip(){	 var sectionHolder = "sectionHolder";	this.createEmptyMovieClip(sectionHolder, this.getNextHighestDepth());	var loadListener:Object = new Object();	loadListener.onLoadComplete = function(contentHolder:MovieClip)	{		trace("movie loaded");	};	var contentLoader:MovieClipLoader = new MovieClipLoader();	contentLoader.addListener(loadListener);	contentLoader.loadClip(movieToLoad, sectionHolder);}

Link to comment
Share on other sites

The reason it works inside the loadListener.onLoadComplete function is because that is the only place where the contentHolder variable exists, once that function ends the variable name contentHolder no longer refers to anything. The movie still exists, it just doesn't have a name. You can create a contentHolder variable outside that function then just have the function assign a reference to the movie to the variable. So outside of the createMovieClip function you would have this:var contentHolder = new MovieClip();Then the event handler would do this:

loadListener.onLoadComplete = function(mc:MovieClip)	{		trace("movie loaded");		contentHolder = mc;	};

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...