Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-20-2009, 03:58 PM   #1
ChiWhiteSox56
ChiWhiteSox56
 
Join Date: Oct 2008
Location: Chicago, IL
Posts: 8
Default Trouble dynamically adding movieclips to the stage

Hello all,

I am trying to write some code for someone show wants to be able to control their timeline animation by using the slider component. Everything was going fine until I tried to add the Play and Pause buttons to the stage. I instantiated both movieclips and added "stage.addChild(<mcName>);" but neither clip showsup when I test the movie. I tried removing "stage." but that didn't help either.

I tried to find a solution to my problem online, and while I haven't figured it out yet, it seems that these movieclips might need to be part of a function. This could be totally incorrect, but it's the best guess I have right now.

Any help would be greatly appreciated. My AS code is below. (I couldn't get the .FLA file to zip small enough, but if anyone wants it, I'll find a way.) See comment "// PLAY/PAUSE CODE" for Play/Pause buttons.

Thanks,
Cindy

Code:
//SLIDER CODE

// Import slider and movieclip classes
import fl.controls.Slider;
import fl.events.SliderEvent;
import flash.display.MovieClip;

// Instantiate slider
var mcSlider:Slider = new Slider();

// Add slider to stage
addChild(mcSlider);

// Position slider
mcSlider.move(20,400);

// Set slider size
mcSlider.setSize(280,1);

// Determine slider incrememtal behavior
mcSlider.maximum = mcBall.totalFrames;
mcSlider.liveDragging = true;

// Make animation move in relation to slider
mcSlider.addEventListener(Event.CHANGE, updatemc)
function updatemc(event:Event)
{
	mcBall.gotoAndStop(mcSlider.value)
} // end function updatemc

// Make slider nub match movieclip position
mcSlider.addEventListener(Event.ENTER_FRAME, matchFrames);
function matchFrames(event:Event):void
{
	mcSlider.value = mcBall.currentFrame;
	if(mcSlider.value == mcBall.currentFrame)
	{
		mcBall.play();
	}
	if(mcSlider.value == mcSlider.maximum)
	{
		mcBall.stop();
	}
}

// PLAY/PAUSE CODE

// Instantiate buttons
var mcPlay:MovieClip = new MovieClip();
var mcPause:MovieClip = new MovieClip();

// Add Play and Pause buttons to stage
stage.addChild(mcPlay);
stage.addChild(mcPause);

// Position Play and Pause buttons to stage
mcPlay.x = 160;
mcPlay.y = 334;
mcPause.x = 160;
mcPause.y = 334;

// Make "Play" button invisible whie movieclip plays
mcPlay.visible = false;
mcPause.visible = true;

// Play/pause button functionality - Two functions
mcPause.addEventListener(MouseEvent.CLICK, pauseBall)
function pauseBall(event:MouseEvent):void
{
	mcPlay.visible = true;
} // end function pauseBall

mcPlay.addEventListener(MouseEvent.CLICK, playBall)
function playBall(event:MouseEvent):void
{
	mcPlay.visible = false;
} // end function playBall
ChiWhiteSox56 is offline   Reply With Quote
Old 10-20-2009, 04:01 PM   #2
raydowe
Senior Member
 
Join Date: Jan 2007
Posts: 357
Default

Not sure what your expecting or maybe I'm just missing something. I had a quick look at your code and you are creating two empty movie clips and adding them to the stage, so your not going to see anything whether they are added or not.

Are you getting an error?
raydowe is offline   Reply With Quote
Old 10-20-2009, 04:08 PM   #3
ChiWhiteSox56
ChiWhiteSox56
 
Join Date: Oct 2008
Location: Chicago, IL
Posts: 8
Default

No, I'm not getting an error.

What's happening is that the ball movieclip is showing up, and the slider used to control it shows up and works properly (this was added in the //SLIDER CODE part), but the Play and Pause icons do not.

I'm curious about the movieclips being empty. That sounds like it could very well be the problem, but I'm afraid I don't know how to fix that. I thought that what I did would put the Play and Pause on the stage, but clearly that's not the case.
ChiWhiteSox56 is offline   Reply With Quote
Old 10-20-2009, 04:14 PM   #4
raydowe
Senior Member
 
Join Date: Jan 2007
Posts: 357
Default

Nope,
ActionScript Code:
// Instantiate buttons var mcPlay:MovieClip = new MovieClip(); var mcPause:MovieClip = new MovieClip(); // Add Play and Pause buttons to stage stage.addChild(mcPlay); stage.addChild(mcPause);

This is just making two empty movie clips and putting them on the stage. Where do the play and pause buttons exist right now?
raydowe is offline   Reply With Quote
Old 10-20-2009, 04:32 PM   #5
ChiWhiteSox56
ChiWhiteSox56
 
Join Date: Oct 2008
Location: Chicago, IL
Posts: 8
Default

Right now, the Play and Pause movieclips are in the Library as mcPlay and mcPause. I have Export for Actionscript and Export in Frame 1 checked for both, and the Class for each is mcPlay or mcPause. Both have a Base Class of flash.display.MovieClip.
ChiWhiteSox56 is offline   Reply With Quote
Old 10-20-2009, 04:50 PM   #6
raydowe
Senior Member
 
Join Date: Jan 2007
Posts: 357
Default

Ok, sounds like your setup right, just had some wrong code.

You want:
ActionScript Code:
var mcPlay_mc = new mcPlay(); var mcPause_mc = new mcPause();

Because you are exporting those symbols for AS and giving them a class, you want to make a new instance of each of those classes.
raydowe is offline   Reply With Quote
Old 10-20-2009, 06:28 PM   #7
ChiWhiteSox56
ChiWhiteSox56
 
Join Date: Oct 2008
Location: Chicago, IL
Posts: 8
Default

Beautiful!! Worked like a charm.

Thanks so much for your help - I learned something today!
ChiWhiteSox56 is offline   Reply With Quote
Old 10-20-2009, 06:58 PM   #8
raydowe
Senior Member
 
Join Date: Jan 2007
Posts: 357
Default

np, glad I could help
raydowe 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 02:06 PM.

///
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.