Skip to main content
Participant
September 5, 2009
Question

SwapChildren Glicht

  • September 5, 2009
  • 6 replies
  • 1241 views

Hi there!.

Well i have something that a just can make it works... it's about the z-index of children object in a movie clip. When i click on a item (movie clip) i want to "zoom it" (just sclaing by 2.0 the width and height) and to show above others items that are nears.. The thing is when i move the items, the are like duplicated.. i don't why, but copies of the movie clips remains there....

I put here the important parts... the problems are in the methods sendToFront and sentToBack... basically the function swapChildren has this glicht or i  am doing (most probably) something bad.

function setToFront (object:MovieClip) : void
{
    removeEventListener(MouseEvent.CLICK,btnLinkClickHide);   
    var prevMc:MovieClip = (this.getChildAt (3) as MovieClip);
    swapChildren(prevMc,object);
}

function setToBack (object:MovieClip) : void
{
    addEventListener(MouseEvent.CLICK,btnLinkClickHide);   
    var prevMc:MovieClip = (this.getChildAt (3) as MovieClip);
    swapChildren(object,prevMc);
}

setToFront is exectued from a callback from the movieclip that is seleting the user. And setToBack is executed from a Timer when finalizes (i am using intervals, not real Timers classes) restoring the moviecliup the normal size. See the .swf for help!

Thanks for advance if you reach this point!! .

See ya!

This topic has been closed for replies.

6 replies

Participant
September 8, 2009

Mike: I try what you said but doesn't work.. thanks away!!!!.

I guess i sort it out people... i im pretty new to ActionScript and still i never understand very well the principles of scripting.. i am just trowing everying over stage, doing motions, and with the knowledge of computers science i got from my current dreggre i program some basic event based flow, doing the roll out, roll over, and click states. with callbacks and flags.. but leaning, basically, over the timeline for do the animations, and not actionScript. When i want to rewind a movie clip, and do some smooth cool effects i use timers, basicaly the execute the method prevFrame "n" times to go back to the initial state.

Well..., like a was saying, i guess the problems came because i have in the same layer i have two movies (one at the frame "n" and other at frame "m", where "n" < "m", and i motion tween bettew both for doing the "came out" "came it" animation), from the same Instance of the same Movie Clip, and the name of the Instance is exactly the same... i think.. that maybe, this is bugging the thinks with actionScript,.. beacuse i am working in the time line with two objects naming equals, and in actionScript referening to one of they, cuz actionScript just don't know how to handle (like any other programing lenguage) a reference to two diferent variables with same name, in this case the variables are in fact movie clips.

I don't very well.. but if someone can tell me if this is true, well.. thanks.. if not, thanks equals, and why.. a lot of thanks!! jejeje.

Good Luck and thanks!.

Participant
September 5, 2009

First, Thanks guys!!.

Ned: mmm i don't understand your question... mmm i can send you the code and you may find the anwser... pliz forgive me, but i am learning..

Andrei: I try what you said, but that "remove" the movie clip that i click!.


I will send yyou the code. So you both can see it, and perphaps tell me what is happening... you will find that i am using the timeline and actionScritp half and half... not pure one or another.. like a mix... i hope that not make things harder to read.


P.D: Change efecto.txt to efecto.fla, i don't what is happening but the server don't let me upload the .fla file

Thanks a lot again!!.

See you!

First, Thanks guys!!.


Ned: i show the call sources:


i have the stage:

   1. mcFront (the bealtes photo)
         1. mcGallery (the beatles photo inside that movie clip)
         2. mcFoto1 (the elephant)
         3. mcFoto2 (i forgive obama for that jeje)
         4. mcFoto3 (Supermek2 cumbia group)
         5. mcFoto4 (pocha)


At the mcFoto1, Layer 1, Frame 1:

stop();
var timerId:uint;


addEventListener(MouseEvent.ROLL_OVER,btnLinkOver);
addEventListener(MouseEvent.ROLL_OUT,btnLinkOut);
addEventListener(MouseEvent.CLICK,btnLinkClickShow);


function disable () : void
{
    removeEventListener(MouseEvent.ROLL_OVER,btnLinkOver);
    removeEventListener(MouseEvent.ROLL_OUT,btnLinkOut);
}


function btnLinkOver (event:MouseEvent) : void
{
    trace ("OVER " + this.currentFrame);
    this.buttonMode = true;
    clearInterval (timerId);
    play();
}


function btnLinkOut (event:MouseEvent) : void
{
    trace ("OUT " + this.currentFrame);      
    this.buttonMode = false;
    this.enableOver = true;
    stop();
    clearInterval (timerId);      
    timerId = setInterval (goBackToOut,30);
}


function btnLinkClickShow (event:MouseEvent) : void
{
    trace ("CLICK SHOW " + this.currentFrame);
    clearInterval(timerId);
    removeEventListener(MouseEvent.CLICK,btnLinkClickShow);
    removeEventListener(MouseEvent.ROLL_OVER,btnLinkOver);
    removeEventListener(MouseEvent.ROLL_OUT,btnLinkOut);
    (this.parent as MovieClip).setToFront (this); <-- THE CALL!
    this.gotoAndPlay("CLICK");  
}


function btnLinkClickHide (event:MouseEvent) : void
{
    trace ("CLICK HIDE " + this.currentFrame);  
    removeEventListener(MouseEvent.CLICK,btnLinkClickHide);  
    clearInterval(timerId);
    timerId = setInterval (goBackToOver,30);
}

// thinks to do smooth animation betten out and over states
function goBackToOut () : void
{
    if (currentLabel != "OUT")  
        prevFrame();
    else
        clearInterval(timerId);
}


function goBackToOver () : void
{
    if (currentLabel != "OVER")  
        prevFrame();
    else
    {
        clearInterval(timerId);
        checkMouseOut();
        addEventListener(MouseEvent.ROLL_OVER,btnLinkOver);
        addEventListener(MouseEvent.ROLL_OUT,btnLinkOut);
        addEventListener(MouseEvent.CLICK,btnLinkClickShow);
        (this.parent as MovieClip).setToBack (this);
    }
}


/* check when the zoom out finish the position of the mouse and eventualy move to out state

if the mouse leaves the photo*/

function checkMouseOut ()
{
    var _stage:Stage = (this.stage as Stage);
    if    (!(this.hitTestPoint (_stage.mouseX,_stage.mouseY,true)))
    {
        clearInterval (timerId);      
        timerId = setInterval (goBackToOut,30);
    }
    else
    {
        gotoAndPlay("OVER");
    }
}

At mcFoto1, layer 1, at the last Frame (where clicks ends):

addEventListener(MouseEvent.CLICK,btnLinkClickHide);
stop();

At mcFront,Layer 1, Frame1:

stop();
var timerId:uint;

function enable () : void
{
    addEventListener(MouseEvent.ROLL_OVER,btnLinkOver);
    addEventListener(MouseEvent.ROLL_OUT,btnLinkOut);
}

function disable () : void
{
    removeEventListener(MouseEvent.ROLL_OVER,btnLinkOver);
    removeEventListener(MouseEvent.ROLL_OUT,btnLinkOut);
}

function setToFront (object:MovieClip) : void
{
    removeEventListener(MouseEvent.CLICK,btnLinkClickHide);   
/*    var prevMc:MovieClip = (this.getChildAt (3) as MovieClip);
    swapChildren(prevMc,object);*/
    //removeChild(object);
    //addChild(object); <-- Action Script Vs Me... ACtionScript wins!! :(
}


function setToBack (object:MovieClip) : void
{
    addEventListener(MouseEvent.CLICK,btnLinkClickHide);   
/*    var prevMc:MovieClip = (this.getChildAt (3) as MovieClip);
    swapChildren(object,prevMc);*/
}

function btnLinkOver (event:MouseEvent) : void
{
    trace ("OVER " + this.currentFrame);
    this.buttonMode = true;
    clearInterval (timerId);
    play();
}

function btnLinkOut (event:MouseEvent) : void
{
    trace ("OUT " + this.currentFrame);       
    this.buttonMode = false;
    this.enableOver = true;
    stop();
    clearInterval (timerId);       
    timerId = setInterval (goBackToOut,30);
}

function btnLinkClickShow (e:MouseEvent) : void
{
    trace ("CLICK SHOW " + this.currentFrame);
    clearInterval(timerId);
    removeEventListener(MouseEvent.CLICK,btnLinkClickShow);
    removeEventListener(MouseEvent.ROLL_OVER,btnLinkOver);
    removeEventListener(MouseEvent.ROLL_OUT,btnLinkOut);
    this.gotoAndPlay("CLICK");
}

function btnLinkClickHide (event:MouseEvent) : void
{
    trace ("CLICK HIDE " + this.currentFrame);   
    removeEventListener(MouseEvent.CLICK,btnLinkClickHide);
    clearInterval(timerId);
    timerId = setInterval (goBackToOver,30);
}


function goBackToOut () : void
{
    if (currentLabel != "OUT")   
        prevFrame();
    else
        clearInterval(timerId);
}

function goBackToOver () : void
{
    if (currentLabel != "OVER")   
        prevFrame();
    else
    {
        clearInterval(timerId);
        checkMouseOut();
        addEventListener(MouseEvent.ROLL_OVER,btnLinkOver);
        addEventListener(MouseEvent.ROLL_OUT,btnLinkOut);       
    }
}

function checkMouseOut ()
{
    var mcParent:MovieClip = (this.parent as MovieClip);
    if    (!(this.hitTestPoint (mcParent.mouseX,mcParent.mouseY,true)))
    {
        clearInterval (timerId);       
        timerId = setInterval (goBackToOut,30);
    }
}

Andrei: I try what you said, but that "remove" the movie clip that i click!.

I will send yyou the code. So you both can see it, and perphaps tell me what is happening... you will find that i am using the timeline and actionScritp half and half... not pure one or another.. like a mix... i hope that not make things harder to read...

I hope to reach this point.. and hopely understand the code guys!! .

P.D:i don't what is happening but the server don't let me upload the .fla file. I attach i file showing that i had doing a work around to solve the thinks, but using the flash timeline (Not action Script) and creating a new layer to show the movie, i put the motions in there.


Thanks a lot again!!.


See you!

MikesNameIsMike
Inspiring
September 6, 2009

this is a little confusing to sort through at 2 AM-  but on a hunch,  could you tell me if it works any better if you change the parameter passed to setToFront in this function from "this" to event.target :

function btnLinkClickShow (event:MouseEvent) : void
{
    trace ("CLICK SHOW " + this.currentFrame);
    clearInterval(timerId);
    removeEventListener(MouseEvent.CLICK,btnLinkClickShow);
    removeEventListener(MouseEvent.ROLL_OVER,btnLinkOver);
    removeEventListener(MouseEvent.ROLL_OUT,btnLinkOut);
    (this.parent as MovieClip).setToFront (this); <-- THE CALL!
    this.gotoAndPlay("CLICK");  

so change

(this.parent as MovieClip).setToFront (this); <-- THE CALL!

to:

(this.parent as MovieClip).setToFront (event.target);

Participant
September 5, 2009

Hey Guys!, first at all thanks!.


Ned Murphy: mmmm i will attach the source code .fla file here if you want to look more closer...what is happening.

Andrei1: the addchild only "removes" the movie that suposes to expand.... :S.

I will add the source code, so if you want and can take a closer look. The file is .fla, but i put a fla.kick beacause the server doesn't allow to upload a.fla fie... :S, strange....

Just remove ".kick" extention... and done .

You will see that i am primary using the timeline for programing and not the ActionScript, but all the roll over and roll out anim and clicks i code then in actionScript, using half code and half the timeline... pretty weird, but i am just learning :S, hope that don't make it harder to read!!.

Thanks a lot!!!

Ned Murphy
Legend
September 5, 2009

mmmmmm... you'll do your self a favor if you show and explain the code you are using... not everyone is willing or able to open files people make available, so providing all the information in your posting opens up more opportunities for people to offer help.

Inspiring
September 5, 2009

1. If you just want to place clicked object on the top - you may want to use addChild which will put it on the top:

function setToFront (object:MovieClip) : void
{
    removeEventListener(MouseEvent.CLICK,btnLinkClickHide);   
    addChild(object);
}

2. Reason for duplication is not in the functions you showed. There is something about transitions you use. Obviously images are duplication (or instantiated more than once).

Ned Murphy
Legend
September 5, 2009

Are you getting any error messages?  If so, it is helpful to copy them into your posting.  Also, if you set the permit debugging option in your Flash Publish Settings the error messages usually have some extra information to offer.

How is the "object" that gets passed as an argument delivered to the functions?  You may need to show the related code.

I notice that you have a fixed z-order value of 3.  Are you certain that what you intend to target is at that location?

Participant
September 5, 2009

I kwow the problem is in the swapChildren function..cuz if i just simple comment those lines.. there is no problem with that... only the objects rise from "below" and not from the "top" like we want .

jejeje

see the other swf with lines commented .

Thanks agains!

See ya!