Remove Movie Clip
I would like to have the user click on a button or movie clip
that takes them to a new scene with multiple questions on it, and
depending on what answer they choose, come back to the main scene
and the button be gone, and replaced with a graphic (that won't
have any function). I thought I could change the alpha of the
graphic (sallylock_mc) from 0 to 100, but its only staying on 0.
And, I can't figure out how to make sally_mc disappear. So far,
here's what I have:
Main scene:
stop();
sallylock_mc._alpha=0
sally_mc.onRelease=function(){
_root.gotoAndPlay("sally");
"sally" scene:
stop();
sallyright_btn.onRelease=function(){
_root.gotoAndPlay("main");
sallylock_mc._alpha=100
OK :)
sally_mc (I changed it to a button, so now it will be
refrenced as sally_btn) exists in the very first frame of the first
scene ("main")of the movie. You have to click it to go to the scene
called "sally" Within the scene called "sally", there is a question
and answers. When the user clicks the right answer, I want them to
go back to the "main" scene, and I want sally_btn to be gone, and
replaced with what looks like a padlock, which I have called
sallylock_mc (it is a movie clip, don't know if it has to be or if
it should be something else.) Also, I want the padlock to only
exist/be visible on the "main" scene. I've found that when I go to
the other scenes, the padlock is there, ontop of everything else.
I've attached the code in "main", and in "sally":
Similar Messages
-
Removing movie clips in arrays
Hi there
I have this code in my Flash file:
for(bubble in bubbleArray){
bubbleArray[bubble]._y -= 3;
if(bubbleArray[bubble]._y < 370){
bubbleArray[bubble].removeMovieClip();
I'm wondering, when I remove the movie clips should I also be popping them from the array?
I have an onEnterFrame function that attaches the movie clips and pushes them into the array, so I'm worried that if I don't pop them the array will continue to increase in size and slow down the movie. Is this the case, or will they be automatically removed from the array by the removeMovieClip() method above?Looks like I spoke too soon. I imagined that removing them from the array would be easy, but I'm struggling.
The movie clip that is removed from its parent clip and should be removed from the array will not always be the first element in the array, and I'll need to remove multiple clips at a time. I've put in a trace action to trace the length of my array, and after about ten seconds it contains about 2500 elements, most of which have already been removed using the removeMovieClip() method. I'm worried this will slow down the movie.
So to clarify: How can I remove these elements from my array when I remove them from the stage?
I tried to include something like:
while(bubbleArray[0] == undefined){
bubbleArray.shift();
but it caused Flash Player to freeze up. Also, if I trace bubbleArray[0] it is only "undefined" before something is pushed into the array. Once the clip has been removed from the stage, the trace just returns a blank line, not "undefined".
I'd appreciate any help.
Here is all my code:
stop();
splash.stop();
var i:Number;
var j:Number = 0;
var minBubbles:Number = 10;
var maxBubbles:Number = 20;
var bottomBubbleLimit:Number = 0;
var topBubbleLimit:Number = 1;
var bubbleNumber:Number;
var bubbleX:Number;
var bubbleY:Number;
var bubbleScale:Number;
var bubbleMinScale:Number = 30;
var bubbleMaxScale:Number = 100;
var fewerBubbles:Number;
var ring:String;
var ringArray:Array = [ringAnimation.ring1, ringAnimation.ring2];
var bubbleArray:Array = [];
ringAnimation.onEnterFrame = function(){
for(ring in ringArray){
if(ringArray[ring]._y > 370){
bubbleNumber = (minBubbles + (Math.random() * (maxBubbles - minBubbles)));
for(i = 0; i < bubbleNumber; i++){
bubbleX = ((ringArray[ring]._x - (ringArray[ring]._width / 2)) + (Math.random() * ringArray[ring]._width));
bubbleY = ((ringArray[ring]._y - (ringArray[ring]._height / 2)) + (Math.random() * ringArray[ring]._height));
bubbleScale = bubbleMinScale + (Math.random() * (bubbleMaxScale - bubbleMinScale));
ringAnimation.attachMovie("bubble", "bubble" + String(j), this.getNextHighestDepth(), {_x:bubbleX, _y:bubbleY, _xscale:bubbleScale, _yscale:bubbleScale});
bubbleArray.push(ringAnimation["bubble" + String(j)]);
j++;
for(bubble in bubbleArray){
bubbleArray[bubble]._y -= 3;
if(bubbleArray[bubble]._y < 370){
bubbleArray[bubble].removeMovieClip();
trace(bubbleArray.length);
if(ringAnimation._currentFrame == 6){
splash.gotoAndPlay(1);
}else if(ringAnimation._currentFrame == 12){
splash.gotoAndPlay(1);
fewerBubbles = setInterval(reduceBubbles, 600);
function reduceBubbles(){
if(minBubbles > bottomBubbleLimit){
minBubbles--;
if(maxBubbles > topBubbleLimit){
maxBubbles--;
if(minBubbles == bottomBubbleLimit && maxBubbles == topBubbleLimit){
clearInterval(fewerBubbles); -
OK...here's my problem... I am making a portfolio site and I
have my thumbnails being created dynamically through XML...very
similar to the galleries example in the Sample and Tutorials. Only
problem is that I have multiple keyframes with different thumbnails
that need to be displyed through a different XML file. I got it to
work but the thumbnails from the first frame are still showing on
the second frame...How do I remove the dynamically created movie
clips?OK...here's the code...At thebottom of the document, I need
to remove the clips created on the next button. This is the same
code from the gallery sample file; I just added my own XML file.
stop();
import mx.transitions.*;
_global.thisX = 30;
_global.thisY = 70;
_global.stageWidth = 600;
_global.stageHeight = 400;
var gallery_xml:XML = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success:Boolean) {
try {
if (success) {
var images:Array = this.firstChild.childNodes;
var gallery_array:Array = new Array();
for (var i = 0; i<images.length; i++) {
gallery_array.push({src:images
.firstChild.nodeValue});
displayGallery(gallery_array);
} else {
throw new Error("Unable to parse XML");
} catch (e_err:Error) {
trace(e_err.message);
} finally {
delete this;
gallery_xml.load("gallery_practices2.xml");
function displayGallery(gallery_array:Array) {
var galleryLength:Number = gallery_array.length;
for (var i = 0; i<galleryLength; i++) {
var thisMC:MovieClip =
this.createEmptyMovieClip("image"+i+"_mc", i);
mcLoader_mcl.loadClip(gallery_array.src, thisMC);
preloaderMC = this.attachMovie("preloader_mc",
"preloader"+i+"_mc", 5000+i);
preloaderMC.bar_mc._xscale = 0;
preloaderMC.progress_txt.text = "0%";
thisMC._x = _global.thisX;
thisMC._y = _global.thisY;
preloaderMC._x = _global.thisX;
preloaderMC._y = _global.thisY+20;
if ((i+1)%5 == 0) {
_global.thisX = 20;
_global.thisY += 80;
} else {
_global.thisX += 80+20;
var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function() {
mclListener.onLoadProgress = function(target_mc, loadedBytes,
totalBytes) {
var pctLoaded:Number =
Math.round(loadedBytes/totalBytes*100);
var preloaderMC =
target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
preloaderMC.bar_mc._xscale = pctLoaded;
preloaderMC.progress_txt.text = pctLoaded+"%";
mclListener.onLoadInit = function(evt:MovieClip) {
evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
var thisWidth:Number = evt._width;
var thisHeight:Number = evt._height;
var borderWidth:Number = 2;
var marginWidth:Number = 8;
evt.scale = 8;
evt.lineStyle(borderWidth, 0x000000, 100);
evt.beginFill(0xFFFFFF, 100);
evt.moveTo(-borderWidth-marginWidth,
-borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth,
-borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth,
thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth,
thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth,
-borderWidth-marginWidth);
evt.endFill();
evt._xscale = evt.scale;
evt._yscale = evt.scale;
evt._rotation = Math.round(Math.random()*-10)+5;
evt.onPress = function() {
this.startDrag();
this._xscale = 30;
this._yscale = 30;
this.origX = this._x;
this.origY = this._y;
this.origDepth = this.getDepth();
this.swapDepths(this._parent.getNextHighestDepth());
this._x = (_global.stageWidth-evt._width+30)/2;
this._y = (_global.stageHeight-evt._height+30)/2;
mx.transitions.TransitionManager.start(this,
{type:mx.transitions.Photo, direction:0, duration:1,
easing:mx.transitions.easing.Strong.easeOut, param1:empty,
param2:empty});
evt.onRelease = function() {
this.stopDrag();
this._xscale = this.scale;
this._yscale = this.scale;
this._x = this.origX;
this._y = this.origY;
evt.onReleaseOutside = evt.onRelease;
mcLoader_mcl.addListener(mclListener);
next_btn.onRelease= function() {
gotoAndStop(2);
back_btn.onRelease= function() {
gotoAndStop(1);
} -
Removing movie clip in a frame
Hello,
I have a timeline with 12 frames, in frame 7 I added a movie clip to the stage:
var pContainer:MovieClip = new MovieClip;
addChild(pContainer);
var myLoader1:Loader = new Loader();
pContainer.addChild(myLoader1);
var myRequest1:URLRequest = new URLRequest("flash/products.swf");
myLoader1.load(myRequest1);
pContainer.x = stage.stageWidth/2 - 380;
pContainer.y = stage.stageHeight/2 - 180;
now, when I hit a button and I go back to frame 2 or any other frame in my movie, this movie clip is on top of everything,
I tried in frame 2:
removeChild(pContainer);
but it doesn't remove the movie clip any ideas?Managing things you create dynamically can be tricky business... I don't yet know why.
One way of doing this is to manually plant pContainer as an empty movieclip symbol in frame 7 rather than creating it dynamically.
Another thing to try would be to use the removeChild command before you move away from frame 7. So you might need to have a conditional in your button that tests the currentFrame value and then executes the removeChild command before moving to the destination frame. -
HELP WITH AS3 Removing Movie Clip
every code i try in the action script to remove a movie clip off of the stage does not work. HELPPPP.
well this is my code to bring it onto the stage
import flash.events.MouseEvent;
pills.addEventListener(MouseEvent.CLICK, arrest)
function arrest(pEvent:MouseEvent):void{
if(pEvent.target==pills){
var carimage: policecar= new policecar();
carimage.x=0;
carimage.y=0;
this.addChild(carimage);
and the remove is under a different clip
stop();
bars1.addEventListener(MouseEvent.ROLL_OVER, barsout)
function barsout(pEvent:MouseEvent):void{
if(pEvent.target==bars1){
this.removeChild(carimage);
even when i add the latter code into the origininal code above it tells me access of undefined property (carimage) -
Removing movie clips with added children
If I have a movie clip added as a child to another movie clip
on the stage, and I remove it's parent, and null all references to
the parent, will both the parent and child movie clip be deleted by
the garbage collector? If so, will it be done on it's regular pass
or by mark and sweep?OK, so if I add a movie clip like this:
function addMovie()
var toAdd:MovieClip = new Example(); // example extends
movieclip
this.addChild(toAdd);
I'm assuming that toAdd will be nulled when the function is
complete, because it's a local variable. Then if I put code inside
the movie clip at a certain frame or in a function in the class
Example to get rid of it:
this.parent.removeChild(this);
I'm assuming that's all i need to do to get rid of it. I
can't null the instance of the class Example using this = null from
inside it, and the only reference to it is the child reference from
the parent.
Am I right or is there more I need to do to make the instance
of example eligible for GC? -
Trying to remove movie clip with collision?
I am creating empty movie clips and populating them with
movie clips that have "drag and drop" functionality. I can create
the empty movie clip and populate it with an external .swf. I've
even got the drag-n-drop handled. But, I'd like to have them delete
or disappear when they are dropped onto a trash can movie clip. I
just can't seem to figure out the code for this. I would greatly
appreciate any help you could give me.
Thanks.you need to perform a hitTest to determine if the item is
within the bounds of your trashcan, you can also use _droptarget,
but I prefer hitTest with a shapeflag parameter. depending on your
code, when you call stopdrag onRelease, run your test there.
the_mc.onRelease = function() {
stopdrag();
if(_level0.trashcan.hitTest(_xmouse, _ymouse, true)) {
this.removeMovieClip();
} -
Hello... I am an ActionScript newbie. I followed a tutorial
from computer arts magazine, to create a portfolio using
actionscript and xml. I linked the portfolio to several scenes in
flash, such as contents and contact details. My problem is that
when I placed a button "back" on the main stage of the portfolio,
to redirect to the contents page, the list of artworks thats
populated from xml remains on the next scene, or any other scene i
link it to. I tried using unload movie clip, but nothing is
working. Please Help. This is my actionscript:
I don't if this helps, but I get this message in the output
panel: Target not found: Target="_root.btn_projectsundefined"
Base="_level0"check the flash help files. there's no better way to debug
your flash applications than the liberal use of the trace()
function.
for example: -
Cant remove movie clip in preloader
For some reason the mc is not removed from the stage when my preloader is finished loading ...
function Preloader(event:ProgressEvent):void {
var mc:preloader = new preloader();
var percent:Number=Math.round(event.bytesLoaded/event.bytesTotal*100);
addChild(mc);
if (percent==100) {
removeChild(mc);
xml_loader.removeEventListener(ProgressEvent.PROGRESS, Preloader);
Am I missing something here?yes.
each time Preloader() is called you're creating a new preloader instance (all with the same reference, mc). so, if you call Preloader() 25 times, you're adding 25 instances of mc and, on the final call to Preloader(), you remove one mc instance and stop the calls to Preloader().
to remedy, use:
var mc:preloader=new preloader();
addChild(mc);
function Preloader(event:ProgressEvent):void {
var percent:Number=Math.round(event.bytesLoaded/event.bytesTotal*100);
// do something with mc to reflect percent
if (percent==100) {
removeChild(mc);
xml_loader.removeEventListener(ProgressEvent.PROGRESS, Preloader); -
I have this bit of code all by itself in a frame on the main
timeline
square.removeChild(squarechild);
it works great if squarechild exists. but if squarechild
doesn't exist the main timeline just stops. In AS3 how do you say
"if squarechild exists, remove it, if it doesn't, just keep going"?
Thanks for your helpIf you look just a little ways down the forum page, you'll
find some info that may help. Here's the link in case it's not
obvious:
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=665&threadid =1428651&enterthread=y -
How do I remove a the contents of a movie clip created using loadClip?
I have a Flash site that loads specific SWFs into a movie
clip called "content_mc" based on a button click. I do this using
the "loadClip" method. I then remove (I thought) the SWF from the
movie clip with "unloadClip" and replace it with a new SWF using
"loadClip." All seemed to be working fine, but now I see that
scripts from a SWF that I thought I unloaded are still running.
I'm sure this is due to my lack of understanding of what
"loadClip" and "unloadClip" are doing. And there certainly may be a
better way to do what I want to do... but such is life. What is the
method to delete a the contents of a movie completely from memory?
or is there a better way to do what I want to do?
Thanks for your help,
DavidNope you understand more or less correctly. unloadClip takes
away the contents that loadClip placed. However there are certain
things that don't go away.
My guess is that you have some setIntervals. Those must be
cleared (clearInterval) before you do the unloadClip.
Or perhaps you have set up some listeners? Again those must
be removed. -
Hi,
On the main timeline, I have the following code:
external_btn.addEventListener(MouseEvent.CLICK, showMenu);
function showMenu(e:MouseEvent):void
var myMovieClip:MovieClip = new Member();
addChild(myMovieClip);
myMovieClip.x = 597.95;
myMovieClip.y =359.15;
in the internal movie clip, that I linked it to Member:
In the member movie clip, I have the following code to remove the movie clip that was created in the main timeline of the root movie clip.
release1_btn.addEventListener(MouseEvent.CLICK, goBack1);
function goBack1(e:MouseEvent):void
MovieClip(root).removeChild(myMovieClip);
I received the following compiler error:
1120: Access of undefined property myMovieClip.
Please help me know how to resolve this error message.
Thanks,
Robert.that's (coding on more than one timeline) not good coding style, but this will correct your error and the prevent a few more:
release1_btn.addEventListener(MouseEvent.CLICK, goBack1);
function goBack1(e:MouseEvent):void
MovieClip(this.parent).removeChild(this); -
I have a movie clip that is called to the stage. The user then clicks a button and music plays. As the music starts, another movie clip is called, a simulation of an equilizer. There are several things that should happen:
1) When the user closes the movie clip the music is supposed to stop playing and the equilizer movie clip is removed. What actually happens is the music stops playing but the equilzer movie clip is not removed.
2) When the music is finished playing the equilzer is supposed to be removed from the stage and the play button is reactivated. But none of that happens. When I click on the movie clip a second time equilizer is still there and the play button is not reactivated.
Here's the code that calls the movie clip to the stage.
stage.addEventListener(MouseEvent.MOUSE_DOWN, goButtons);
function goButtons(event:MouseEvent):void
if (event.target == Song_bnt)
SoundMixer.stopAll();
addChild(myPlaySong);
myPlaySong.x = 304;
myPlaySong.y = 105;
//event.stopImmediatePropagation();
Here's the code in the movie clip:
import flash.media.Sound;
import flash.events.Event;
stop();
var playRayJaySong:RJSong;
var playRayJaySongChannel:SoundChannel;
var equilizer:Equilizer;
equilizer = new Equilizer();
playRayJaySong = new RJSong();
//Plays music, inactivates buttons, and adds the equilizer to the stage.
PlaySongRJClip.addEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
function songPageButton(event:Event):void
playRayJaySongChannel = playRayJaySong.play();
PlaySongRJClip.visible = false;
ClicktoPlaySong.visible = false;
addChild(equilizer);
equilizer.x = 269;
equilizer.y = 246;
//Removes the equilizer from the stage when the music is complete.
PlaySongRJClip.addEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
function rjSoundComplete(e:Event):void
PlaySongRJClip.visible = true;
ClicktoPlaySong.visible = true;
removeChild(equilizer);
//Removes the equilizer and event listeners from stage and calls dispatch event to close the movie clip.
closeSong_bnt.addEventListener(MouseEvent.MOUSE_DOWN, CloseSong);
function CloseSong(event:MouseEvent):void
removeChild(equilizer);
dispatchEvent(new Event("RemoveMSong"));
PlaySongRJClip.removeEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
PlaySongRJClip.removeEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
//Removes the MovieClip from the stage when the user clicks on the close button inside the MovieClip.
myPlaySong.addEventListener("RemoveMSong", RemoveSongClip);
function RemoveSongClip(e:Event):void
SoundMixer.stopAll();
removeChild(myPlaySong);
Any thoughts?I figured out the problem. Here's how I reorganized the code (all in one frame).
//Code for Ray Jay song.
var playRayJaySong:RJSong;
var playRayJaySongChannel:SoundChannel;
playRayJaySong = new RJSong();
myPlaySong.equilizer_inst.visible = false;
//Plays the song.
myPlaySong.PlaySongRJClip.addEventListener(MouseEvent.MOUSE_DOWN, songPageButton);
function songPageButton(event:Event):void
playRayJaySongChannel = playRayJaySong.play();
playRayJaySongChannel.addEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
myPlaySong.equilizer_inst.visible = true;
myPlaySong.PlaySongRJClip.visible = false;
myPlaySong.ClicktoPlaySong.visible = false;
//Removes the MovieClip from the stage when the user clicks on the close button inside the MovieClip.
myPlaySong.closeSong_bnt.addEventListener(MouseEvent.CLICK,RemoveSongClip);
function RemoveSongClip(e:Event):void
SoundMixer.stopAll();
removeChild(myPlaySong);
myPlaySong.equilizer_inst.visible = false;
myPlaySong.PlaySongRJClip.visible = true;
myPlaySong.ClicktoPlaySong.visible = true;
playRayJaySongChannel.removeEventListener(Event.SOUND_COMPLETE, rjSoundComplete);
//Resets all of the movieclips to their orginal state.
function rjSoundComplete(e:Event):void
myPlaySong.equilizer_inst.visible = false;
myPlaySong.PlaySongRJClip.visible = true;
myPlaySong.ClicktoPlaySong.visible = true;
Thanks all for your suggests and input. -
How to remove a function on the main timeline within a movie clip
How do you remove a function that is coded on a frame in the main timeline from within a movie clip? I tried this, but no dice:
infoGraphicDisparity.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene);
function fl_ClickToGoToScene(event:MouseEvent):void
parent.removeEventListener (Event.ENTER_FRAME, parent["enterFrameHandler"]);
MovieClip(this.root).gotoAndPlay("disparity");
this is the event I am trying to remove:
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
any help would be appreciated as always.
Thanks!from any frame (that executes after enterFrameHandler is defined) in any display object in the display list
stage.removeEventListener(Event.ENTER_FRAME, MovieClip(root).enterFrameHandler); -
Remove attached clip and go to a frame on a main movie
I am attaching a Movie Clip on a Main movie wthi sthis:
exit_btn.addEventListener(MouseEvent.CLICK, fexit, false, 0, true);
function fexit(e:MouseEvent):void{
var mc:alert_mc=new alert_mc();
mc.x=320;
mc.y=210;
addChild(mc);
I need to make the Main movie go to frame 6 and remove the attached clip when I click on yep_btn button. The code on the attached clip is:
nope_btn.addEventListener(MouseEvent.CLICK, cancelunloadexitb);
yep_btn.addEventListener(MouseEvent.CLICK, unloadexitb);
function cancelunloadexitb(e:MouseEvent):void {
var snd:sound1 = new sound1();
snd.play();
this.parent.removeChild(this);
function unloadexitb(e:MouseEvent):void {
var snd:sound1 = new sound1();
snd.play();
I NEED CODE HERE
function errorF(e:IOErrorEvent):void{
trace(e);
Any ideas?If that code is inside the alert_mc object, then you can try...
function unloadexitb(e:MouseEvent):void {
var snd:sound1 = new sound1();
snd.play();
MovieClip(parent).gotoAndStop(6);
MovieClip(parent).removeChild(this);
Another way to do it would be to just have the alert_mc dispatch an event that you assign a listener for in the main, and have the main event handler function for that listener deal with removing the child and moving on its own timeline.
Maybe you are looking for
-
HI All, I am using the Data Template to publish output. Based on Data Template.xdo <?xml version = '1.0' encoding = 'utf-8'?> <report version="1.1" xmlns="http://xmlns.oracle.com/oxp/xmlp" defaultDataSourceRef="CNE1"> <title>Based on Data Template</t
-
I want to check is it possible to run scan Inventory on Satelite server on SLES 10 SP2? Which agent to install if I want to run Inventory scan on linux?
-
Hello Everyone, We are trying to prototype the WebChannel part of CRM 7.0. However, as part of the prototype we'd like to leverage our SAP ECC 6.0 system to connect the CRM system to. But we are not sure what impact does connecting CRM to ECC will ha
-
Hi, One my clients 1841 Router giving following error on the Router, when i have checked after after seeing this error it may cause due to error some momory leak issue. Since its running almost newer version of IOS, can you please suggest which versi
-
Hello, I recently had my machine reimaged and I'm trying to configure it to execute Java class files from the command prompt. After manipulating the PATH and CLASSPATH system variables I was able to get it to the point where I can compile .JAVA sourc