Playing a movie clip to its full with mouse over - actionscript-3

In Adobe Flash and ActionScript 3.0, I have a movieclip within a button. I want to play the entire movie clip upon mouse over.
However, the movieclip plays only untill the mouse is over. I want to play the movie clip till the end if the mouse was there.
Any help is appreciated.
I found a blog but, it is valid for AS2 only. This is what I want to do, but with AS3 : EchoEcho
I am a noob for flash and I dont know what to share for this kind of problem. I will provide anything that is needed for solving the problem
Thanks

To make it simple...
If you have an instance named "your_mc" that contains your animation (a MC named your_symbol in the library and you have a tween in the instance named "your_mc"
If the MovieClip is placed on the stage, You may try this.
import flash.display.MovieClip;
import flash.events.MouseEvent;
var your_mc:MovieClip = your_mc;
your_mc.stop()
var clipStopped:Boolean = true;
your_mc.addEventListener(MouseEvent.MOUSE_OVER,playStopClip);
your_mc.addEventListener(MouseEvent.MOUSE_OUT,playStopClip);
function playStopClip(e:MouseEvent):void{
switch (clipStopped) {
case false:
clipStopped = !clipStopped;
break;
case true:
clipStopped = !clipStopped;
break;
}
if (!clipStopped){
your_mc.gotoAndPlay(1);
}else{
your_mc.gotoAndStop(1);
}
}
Be careful this is not Class Based, and should be considered as a basic example!
If You want something more specific, please, edit Your question!
Really basic example here:
fla file
swf file
This is not clean, so, just edit Your question if You want something more efficient please.
If you want to play the entire MovieClip, just check MC.currentFrame and MC.total frames and add a Boolean value to check this.
So the MC cannot stop before the end of the animation.
Best regards.
Nicolas
[EDIT]
This will play Your MovieClip to the end when the Mouse is over...
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
var isRunning:Boolean = false;
var your_mc:MovieClip = your_mc;
your_mc.stop()
var clipStopped:Boolean = true;
your_mc.addEventListener(MouseEvent.MOUSE_OVER,playStopClip);
function playStopClip(e:MouseEvent):void{
if(clipStopped && isRunning==false){
trace("is Running = " + !isRunning)
your_mc.gotoAndPlay(1);
clipStopped = !clipStopped;
isRunning = true
your_mc.addEventListener(Event.ENTER_FRAME,changeStatus);
}
}
function changeStatus(e:Event):void{
if (your_mc.currentFrame == your_mc.totalFrames){
isRunning = false;
clipStopped = true;
your_mc.gotoAndStop(1);
your_mc.removeEventListener(Event.ENTER_FRAME,changeStatus);
}
trace(your_mc.currentFrame + " / " + your_mc.totalFrames);
}
fla file
swf file
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
var isRunning:Boolean = false;
var your_mc:MovieClip = your_mc;
your_mc.stop()
var clipStopped:Boolean = true;
your_mc.addEventListener(MouseEvent.MOUSE_OVER,playStopClip);
function playStopClip(e:MouseEvent):void{
if(clipStopped && isRunning==false){
trace("is Running = " + !isRunning)
your_mc.gotoAndPlay(1);
clipStopped = !clipStopped;
isRunning = true
your_mc.addEventListener(Event.ENTER_FRAME,changeStatus);
}
}
function changeStatus(e:Event):void{
if (your_mc.currentFrame == your_mc.totalFrames){
isRunning = false;
clipStopped = true;
your_mc.stop();
your_mc.removeEventListener(Event.ENTER_FRAME,changeStatus);
}
trace(your_mc.currentFrame + " / " + your_mc.totalFrames);
}
fla file
swf file
No more MouseEvent.MOUSE_OUT here if you want to play Your Movie Clip to the last frame.
The MouseEvent.MOUSE_OVER is only available when Your Movie clip animation is completed.
So as You didn't give feedback and the question is unclear : "DownVote"
[/EDIT]

Related

Adobe Flash/ActionScript 3.0 moving to next scene but nothing plays

I've searched endlessly for an answer but can't seem to find one.
I'm building a flash presentation for a client. It's got about 15 scenes, the .fla file is 200MB before publishing (26MB afterward). It's a pretty simple operation; I'have a pause/play & replay button, and once the scene is completed a next & replay button appears in the center of the stage.
My issue is when I get to about the 8th scene, halfway through. All my tweens and buttons stop working. Simple fade-in text doesn't come up and my pause/play & replay no longer function. I've tried shifting around scenes to see if it was anything in particular, but no matter what order and what scenes it always stops halfway through the 8th. I don't get any error notifications before, after or during the play. Tracing tells me that the button has been clicked and it's moved to the next scene but it simply will not play. Adding a play(); comment at the first frame of the next scene has not helped either.
Here are my functions that are on Scene 1 Frame 1
function pause_movie(event:MouseEvent):void {
stop();
playBtn.visible = true;
pauseBtn.visible = false;
}
function play_movie(event:MouseEvent):void {
play();
playBtn.visible = false;
pauseBtn.visible = true;
}
function replay_movie(event:MouseEvent):void {
gotoAndPlay(1);
}
function next_movie(event:MouseEvent):void {
this.nextScene();
trace("next_movie " + this.currentScene.name);
}
And then I just add event listeners when my buttons appear per scene
import flash.events.MouseEvent;
//Hide play button to start
playBtn.enabled = true;
pauseBtn.enabled = true;
playBtn.visible = false;
pauseBtn.addEventListener(MouseEvent.CLICK, pause_movie);
playBtn.addEventListener(MouseEvent.CLICK, play_movie);
replayBtn.addEventListener(MouseEvent.CLICK, replay_movie);
Any help is appreciated! Thank you!
I've created a new flash file with a blank canvas (just page number and next button). I'm loading the audio externally now as per #VC.One 's comment and the program stops working at the same scene regardless of which audio file I put in there.
Here is my updated code:
import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
var channel:SoundChannel = new SoundChannel;
var s:Sound = new Sound();
function newSound() {
s.removeEventListener(Event.COMPLETE, onSoundLoaded);
s = new Sound();
s.addEventListener(Event.COMPLETE, onSoundLoaded);
}
function onSoundLoaded(e:Event):void
{
channel = s.play();
}
function next_movie(event:MouseEvent):void
{
channel.stop();
try {
s.close();
}
catch(e:Error) {
trace("File already loaded");
}
this.nextScene();
trace("next_movie " + this.currentScene.name);
}
and each scene starts with:
pageNum.text = this.currentScene.name;
skipBtn.addEventListener(MouseEvent.CLICK, next_movie);
newSound();
s.load(new URLRequest('audio/ISB page 17 tk 1.mp3'));
Finally solved this issue. The scenes added together were more than the 16k frames Flash is apparently limited to. I had to convert each scene into a movieclip and put them in each of their own frame all in one scene with a bit of coding to play each one after the previous one finished. Everything works fine now. Thanks guys!

CS5+AS3 Preloader starts at 50%; no clue why

I know there are a lot of previous topics about preloaders and I've tried to follow every one of them but I still get the same problem (well they have helped me go from 80% -> 50%)
Right now it starts at 61450 / 125207 which is about 50%.
Here is my Main Document (default class file for the entire project) class:
public class MainDocument extends MovieClip
{
private var preloader:Preloader;
private var sB:startButton;
public function MainDocument()
{
preloader = new Preloader();
preloader.x = 300;
preloader.y = 400;
addChild(preloader);
loaderInfo.addEventListener(Event.COMPLETE,addStartButton,false,0,true);
}
private function addStartButton(e:Event):void
{
sB = new startButton();
sB.x = 300;
sB.y = 450;
sB.addEventListener(MouseEvent.CLICK,sMainMenu,false,0,true);
addChild(sB);
loaderInfo.removeEventListener(Event.COMPLETE,addStartButton);
}
private function sMainMenu(e:Event):void
{
sB.removeEventListener(MouseEvent.CLICK,sMainMenu);
removeChild(sB);
removeChild(preloader);
sB = null;
preloader = null;
var menuScreen = new MenuScreen();
addChild(menuScreen);
//I have heard that the following code might work better:
//var menuScreen:Class = getDefinitionByName("MenuScreen") as Class;
//addChild(new menuScreen() as DisplayObject);
}
}
And the Preloader that it attaches:
public class Preloader extends MovieClip
{
public function Preloader()
{
addEventListener(Event.ENTER_FRAME,Load);
}
private function Load(e:Event):void
{
//"bar" is a movieclip inside the preloader object
bar.scaleX = loaderInfo.bytesLoaded/loaderInfo.bytesTotal;
//"percent" is a dynamic text inside the preloader object
percent.text = Math.floor(loaderInfo.bytesLoaded/loaderInfo.bytesTotal*100)+"%";
trace(loaderInfo.bytesLoaded+" / "+loaderInfo.bytesTotal);
if (loaderInfo.bytesLoaded == loaderInfo.bytesTotal)
{
removeEventListener(Event.ENTER_FRAME,Load);
}
}
}
-> Nothing is set to Export on Frame 1 except for the Preloader
-> No objects exist on the first frame; the only code on first frame is stop();
-> I placed a copy of every single MovieClip in the second frame and when the startButton is clicked, a gotoAndStop(3); is run so no one ever sees frame 2.
If anyone knows of anything simple that I could have forgotten, please let me know!
Thanks!
You're tying to use a preloader in the file being preloaded. In that case, there is going to be bloat from the rest of the project's code and assets. The reason you are seeing your preloader seemingly delayed is because a swf must load completely before any code will execute. This includes all assets on stage regardless of what frame they are on, even if you have settings in place to export on something other than frame 1. Instead, try using a blank shell as your preloader. This shell will have nothing in it but the loader code and a preloader graphic or animation. When the load is finished, hide your preloader and add your loaded content to the stage of the shell, or a container movieclip in the shell.
All the following code goes in your shell, which is just another FLA file with nothing in it but this code, and a preloader bar. The dimensions of this file should be the same as the file you are loading into it, ie your original swf file you were trying to preload.
Use it by calling loadSwf( "mySwfNameOrURLToSwf.swf" );
The variable _percent will populate with the current load percentage, which you can correspond to your loading bar scale. Presuming the preloader bar is named "bar", the line bar.visible = false; in the onSwfLoaded function will hide it. addChild( _swf ) adds the loaded swf to the shell's stage. The line _swf.init(); references a function in the loaded swf you will need to add called init() that starts your loaded swf doing whatever it is its supposed to do. Have everything in the loaded swf start on the first frame now, including the init() function.
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.Bitmap;
import flash.net.URLRequest;
import flash.system.ApplicationDomain;
import flash.system.SecurityDomain;
import flash.system.LoaderContext;
import flash.system.Security;
import flash.events.Event;
import flash.events.ProgressEvent;
var _swfLoader:Loader;
var _swf:DisplayObject;
var _percent:Number;
function loadSwf( swfURL:String ):void
{
_swfLoader = new Loader();
var req:URLRequest = new URLRequest( swfURL );
var loaderContext:LoaderContext = new LoaderContext();
loaderContext.applicationDomain = ApplicationDomain.currentDomain;
loaderContext.checkPolicyFile = true;
_swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onSwfProgress);
_swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSwfLoaded);
_swfLoader.load(req, loaderContext);
}
function onSwfProgress( evt:Event ):void
{
_percent = Math.round( ( evt.target.bytesLoaded / evt.target.bytesTotal ) * 100 );
}
function onSwfLoaded( evt:Event ):void
{
_swfLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onSwfProgress);
_swfLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onSwfLoaded);
_swf = _swfLoader.content;
addChild( _swf );
bar.visible = false;
_swf.init();
_swfLoader = null;
}
your code looks ok.
when you are not on a http server, loading process are simulated.
After compiling, press crtl + B.
In menu you can choose the downloading speed and simulate a download by pressing again ctrl+enter.
it might help you to debug your preloader
#Lee Burrows What you said was right but would have been better if you looked at what I mentioned at the end of the code (three bold points)
The solution I used was:
-> I set everything to Export on Frame 2 on my 3 frame document.
-> Removed everything on Frame 2
-> Created a TextField via constructor and used drawRectangle for loading bar
-> No movieclips present on frame 1, and used
var menuScreen:Class = getDefinitionByName("MenuScreen") as Class;
addChild(new menuScreen() as DisplayObject);
instead of the previous code.
The reason why what I had originally didn't work because, as Lee Burrows mentioned, the Export for Actionscript hangs the loading if X = 1 in Export on Frame X, regardless if Export on Frame 1 was checked or not. Changing it to 2 or unchecking Export for Actionscript were the two solutions (except if it isn't exported for actionscript, then its code cant be referenced to).
Preloader starts at about 2% now.

Movieclips clashing with bitmap mask

I am trying to reveal this movie clip image which is originally a bitmap but needs to be used as a bitmap for this purpose. for some reason it's not working ...
It's not throwing any errors... I need this image to be masked as the user presses on it... and later be compared with another bitmap to carry out a function. but for some reason as I mentioned before it's not working out. can somebody please help me?? this is the code for it...
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.BitmapData;
var mouseclick:Number=0;
var maskedbg_mc:maskedbg = new maskedbg ();
var masking:Sprite = new Sprite()
addChild (maskedbg_mc);
maskedbg_mc.x = 18;
maskedbg_mc.y = 343;
var bitmapDataCopy:BitmapData = new BitmapData(742,165,true,0x00FFFFFF);
var b:Bitmap = new Bitmap(bitmapDataCopy);
bitmapDataCopy.draw(maskedbg_mc);
b.mask = masking;
var Testing:BitmapData = new BitmapData(maskedbg_mc.width, maskedbg_mc.height, true, 0x00000000);
addChild(masking);
stage.addEventListener(MouseEvent.MOUSE_DOWN, Pressing);
stage.addEventListener(MouseEvent.MOUSE_MOVE, Moving);
stage.addEventListener(MouseEvent.MOUSE_UP, Lifting);
function Pressing(event:MouseEvent):void {
mouseclick = 1;
}
function Moving(event:MouseEvent):void {
if (mouseclick == 1) {
masking.graphics.beginFill(0x000000);
masking.graphics.drawEllipse(mouseX, mouseY, 70, 60);
masking.graphics.endFill();
}
}
function Lifting(event:MouseEvent):void {
mouseclick = 0;
}
if ( bitmapDataCopy.compare(Testing) ==0 )
{
trace ("Awesomness")
}
Overlooking your code, I notice you are not adding "b" (the masked DisplayObject) to the display list, while you are adding "maskedbg_mc" which actually isn't being masked in your code. Do you have a reason for having these 2 display objects?
I would recommend you following actionscript coding conventions:
http://sourceforge.net/adobe/flexsdk/wiki/Coding%20Conventions/
Your code looks quite confusing when you have both variables and functions with initial letter in uppercase, they look like classes.

AS3 button firing off multiple times if clicked fast only

ok so, i wrote this code:
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import flash.display.Stage;
stop();
var loader:Loader = new Loader();
var defUrlReq = new URLRequest("indexCoontentLoad.swf");
var urlRequest:URLRequest = new URLRequest();
var myLoadedSwf:MovieClip = null;
var swfStage:Stage = this.stage;
/////////////// INITIATE LOADERS ///////////////
loader.load(defUrlReq);
/////////////// START MAIN HANDLER FUNCTION ///////////////
/////IMPORT DEFAULT SWF /////
loader.contentLoaderInfo.addEventListener(Event.INIT, loadedHandler);
function loadedHandler(event:Event){
myLoadedSwf = event.target.content;
addChild(myLoadedSwf);
trace(myLoadedSwf);
myLoadedSwf.gotoAndPlay("intro");
trace("STEP 1 -- ext def swf loaded");
}
///////END IMPORT. ///////////////
///// START LISTENERS AND THEIR FUNCTIONS /////
load1.addEventListener(MouseEvent.CLICK,btn4Clicked);
load2.addEventListener(MouseEvent.CLICK,btn4Clicked);
load3.addEventListener(MouseEvent.CLICK,btn4Clicked);
///// END LISTENERS /////
///// START FUNCTIONS /////
function btn4Clicked(e:MouseEvent):void { //-- START btn4Loaded
if (e.target == load1 || e.target == load2 || e.target == load3) {
myLoadedSwf.gotoAndPlay("outro");
removeChild(myLoadedSwf);
urlRequest = new URLRequest(e.target.name+".swf");
loader.load(urlRequest);
addChild(myLoadedSwf);
}
}
and it works, once clicked, it does what it has to do. Ofcourse, me trying to break it, i found that if i click the buttons fast, it will re-import the external swfs causing me to have multiple instances of the external swf.
so in short, if i click like normal(slow ) ie like a person that clicked to view a section etc, then its fine, if i click fast or repeated clicking ie like a person that double clicks etc, then the problem occurs.
any ideas how to fix this?
thanks in advance.
edit*** heres a link to test file to show what i mean
http://www.somdowprod.net/4testing/flash/tst
When you set doubleClick to enabled on your movieclip, this will work. The Flash runtime will thencheck for you if it is a double click and only trigger your method once. If you want to listen for the double clicks, you can by changing the event handler.
mySprite.doubleClickEnabled = true;
mySprite.addEventHandler(MouseEvent.CLICK, onClick);
Good luck.
You could try adding a boolean variable that is set to false. Once the .swf is loaded then change that variable to equal true. Then don't let the swf be loaded unless it is set to false. That way it'll only be allowed to be loaded once.
var isLoaded:Boolean = false;
function btn4Loaded(e:Event):void
{ //-- START btn4Loaded
if(!isLoaded)
{
if (e.target == load1 || e.target == load2) {
myLoadedSwf.gotoAndPlay("outro");
removeChild(myLoadedSwf);
urlRequest = new URLRequest(e.target.name+".swf");
loader.load(urlRequest);
addChild(myLoadedSwf);
isLoaded = false;
}
}
} // end btn4Loaded.

Switching of depths causes duplication of MC

this is a repost of a previous question with more info this time.
The files: 2shared.com/file/hRKhEiqh/Script_Test.html and 2shared.com/video/UZNmqzXt/a_anconeus.html
This issue is reproducible on my machine with a new .fla project in Actionscript 3.0 in Flash Professional CS5. It's an edit of my original question with more information.
I'm working on a project to load external SWF's and search through instance names for matching keywords, namely 'drag' and 'drop' to identify movieclip matches, then attach event listeners to these MC's which contain the D&D event listeners and code.
The specific problem is the switching of depths for Movieclips nested in dynamically loaded external SWF files.
Where I am having trouble is the specific commands:
swapChildrenAt, setChildIndex, swapChildren, removeChild/addChild. I've tried all four with the same problem of duplication. Let me explain.
When a draggable MC is clicked, it is moved to the top index of the dynamically loaded SWF so it's visible above everything else in that SWF. The problem is that trying any of these commands all duplicate the MC. What happens is this:
MOUSE_DOWN event fires on MC:
Index of target MC is recorded as '2', the index we will switch to is '20' (maximum index of the SWF)
setChildIndex is called on the target MC parent: mc.parent.setChildIndex(mc, (mc.parent.numChildren-1))
MC moves to index 20 then another instance of the MC is created at the layer it was located previously (index 2), this happens after the MOUSE_DOWN event finishes, I'm not sure exactly when.
This duplicate has been confirmed using the EVENT.ADDED_TO_STAGE listener attached to the stage to catch every object of MovieClip types that is added to the stage. I've inspected the SWF to confirm there's no duplicate MovieClips, the traces also confirm this.
Similar posts mention the same duplication problem but no one has a solution that I've found will work in my case.
http://www.kirupa.com/forum/showthread.php?t=359452
http://board.flashkit.com/board/showthread.php?t=775200
http://forums.adobe.com/thread/199983
As a last note, if I comment out the index swap statement, the code works perfectly with the MC simply staying on its lower z-index instead of being on top. Unfortunately that's not going to work as a solution since I'm not building the external SWF's.
To duplicate this behavior, you need an external AS3 SWF with two at least two MC's with instance names "drag01" and "drop01" or something that matches the keywords 'drag' and 'drop'. Point the String variable 'SWF' to that file and you should see the duplication problem.
Thanks and regards
Cameron
Edit: new trimmed code, copied into a blank AS 3.0 file with the same errors.
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.net.URLLoader;
var swf:String = "a_anconeus.swf";
loadSWF(swf);
stage.addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStageReport, true);
stage.addEventListener ( Event.ADDED_TO_STAGE , onAddedToStageReport , true ) ;
function onRemovedFromStageReport (evt:Event)
{
{
trace("REMOVED: " + evt.target.name + " at depth: " + evt.target.parent.getChildIndex(evt.target));
}
}
function onAddedToStageReport (evt:Event)
{
{
trace("ADDED: " + evt.target.name + " at depth: " + evt.target.parent.getChildIndex(evt.target));
}
}
function onDragMouseDown(event:MouseEvent):void
{
var drag:MovieClip = MovieClip(event.target);
var topPosition:uint = drag.parent.numChildren - 1;
trace("click: "+drag.name +", ontarget = "+drag.ontarget + ", current z: " + drag.parent.getChildIndex(drag) + " new z: " + topPosition);
//drag.parent.setChildIndex(drag, topPosition);
var indexToDelete:int = drag.parent.getChildIndex(drag);
//this.parent.removeChild(this);
trace("index to delete: " + indexToDelete +", what's there: " + drag.parent.getChildAt(indexToDelete).name);
drag.startDrag();
//drag.parent.setChildIndex(drag, drag.parent.numChildren-1); //set child depth to top
trace("after change, what's there: " + drag.parent.getChildAt(indexToDelete).name);
//drag.parent.swapChildren(drag, drag.parent.getChildAt(drag.parent.numChildren -1));
}
function onDragMouseUp(event:MouseEvent):void
{
trace("mouse up: "+event.target.name + ", index: " +event.target.parent.getChildIndex(event.target));
var drag:MovieClip = MovieClip(event.target);
drag.stopDrag(); //Movieclips have simple drag methods
}
/*function dragEnterFrameHandler(event:Event):void {
var drag:MovieClip = MovieClip(event.target);
if (drag.mousedown == false)
{
if (drag.onTarget == true)
{
//send it to the drop X/Y
drag.x -= (drag.x - drag.dropon.x)/5;
drag.y -= (drag.y - drag.dropon.y)/5;
}
else if (drag.onTarget == false)
{
drag.x -= (drag.x - drag.homeX)/5;
drag.y -= (drag.y - drag.homeY)/5;
}
}
}*/
function loadSWF(filepath:String)
{
trace("calling loader");
var loader:Loader = new Loader();
var url:String = filepath;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
loader.load(new URLRequest(url));
}
function onAddedToStage ( evt:Event )
{
trace("calling onAddedToStage");
/*if (evt.target is MovieClip) //filter only movieclips
{
var mc:MovieClip = MovieClip(evt.target);
// trace ( "onAddedToStage, evt: " + mc.name + ", " +(mc.parent.numChildren-1) ) ;
if (String(mc.name).indexOf("drag") != -1)
{
var dropString:String = String(mc.name).split("drag").join("drop");
if (mc.parent.getChildByName(dropString))
{
trace("our droptarget: " + mc.dropon);
mc.addEventListener(MouseEvent.MOUSE_DOWN, onDragMouseDown);
mc.addEventListener(MouseEvent.MOUSE_UP, onDragMouseUp);
mc.buttonMode = true;
}
}
}*/
}
function onCompleteHandler(loadEvent:Event)
{
trace("load complete");
var swf:MovieClip = MovieClip(loadEvent.currentTarget.content);
//swf.addEventListener ( Event.ADDED_TO_STAGE , onAddedToStage, true ) ;
//trace("event attached, adding child");
trace("child add started");
addChild(swf);
trace("child add finished");
var children:Number = (swf.numChildren-1);
trace("children: " + children);
for (var i:Number = 0; i <= children; i++)
{
trace("LOOP STARTS HERE");
if (swf.getChildAt(i) is MovieClip)
{
//trace("MC: yes");
var mc:MovieClip = MovieClip(swf.getChildAt(i));
trace("name: " + mc.name);
if (String(mc.name).indexOf("drag") != -1)
{
var dropString:String = String(mc.name).split("drag").join("drop");
if (swf.getChildByName(dropString))
{
trace("removing: " + mc.name);
children--;
swf.removeChild(mc);
trace("removed");
//swf.addChild(mc);
/*mc.addEventListener(MouseEvent.MOUSE_DOWN, onDragMouseDown);
mc.addEventListener(MouseEvent.MOUSE_UP, onDragMouseUp);
mc.buttonMode = true;*/
}
}
}
}
trace("finish function");
}
mystery solved :)
looking at your swf I can see that it has two frames, so as soon as you start dragging, the next frame renders and the object comes back.
to test this I added swf.stop(); to yout onCompleteHandler
I can't open your sample files because I only have CS3, but I can tell you what I think is the most likely cause. When you reparent those clips and then later find they've duplicated, is there any kind of timeline playing that happens in the meantime? Like in this sample fla?
Unintentional cloning
The problem is that when you remove a movieclip from a display list into which it was published, but that display list is in a movieclip that is playing, when the clip re-plays the old frame, or in any other way "expects" the clip to be where it was when you published the fla, it just "clones" it and puts it back... or rather, it "clones" what it knows it would have been if you hadn't moved it already. That's what I've illustrated in the fla above. I re-parent the foo clip, randomly place it somewhere onstage, then when the movieclip cycles back to frame 1 it finds that "there should be a foo here, but there's not. better make one."