Jump to content
Sign in to follow this  
dnainby

createMovieClip()- control from a button

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);}

Share this post


Link to post
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;	};

Share this post


Link to post
Share on other sites

Thought it was "sometimes you can't see the trees for the wood"

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...