A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Detect MC in MC

  1. #1

    Detect MC in MC

    I have added a child MC in frame 20 of my file. Within this MC, I have added another child MC. In frame 1, I would like to detect to see if the second MC is on the stage. I have tried using the the stage.contain(secondMC), but I keep getting the error 'Access of undefined property secondMC'. I believe this is because I have declared the secondMC within the firstMC by using var secondMC:MovieClip = new secondMC1().

    I am wondering how I am able to detect my secondMC in frame 1?
    ~~~~~jOn waZ hErE~~~~~

  2. #2
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    I'm afraid the timeline can not "predict" what it's going to contain later on.
    If the second MovieClip if defined on the first frame, then getting to it should not be a problem, but then you probably wouldn't be asking this..

    This will not work, but it's just something I noticed, you say you add n°2 to n°1, and then you check to see if the stage contains n°2.
    That will always return false since n°2 is inside of n°1 and not on the stage

    You can try to use an EnterFrame which searches for a currentFrame of 20 and then tries to find mc2, but that's not what you want, right?
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  3. #3
    Unfortunately, the second movie clip is not defined in the first frame which is why I am having this difficulty.

    I have not heard of EnterFrame, but I will do some research into that to see if that will work.

    Let me clarify my situation a bit more. I am creating a flash website. On layer1, I have a single key frame that spans over 20 frames which contains the action script coding to navigate between my different pages. On layer2, I have the action script coding that control the contents on each of the individual pages. In a way, I am not asking the timeline to 'predict' whether or not something is going to happen - I am just asking to see if the movie clip is on the stage. I don't know if I'm making sense.
    ~~~~~jOn waZ hErE~~~~~

  4. #4
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    I understand if the MovieClip makes its first appearance on the 20th frame, you can't tell if it's around on any frame before that..

    This is how it would look with an EnterFrame, but I don't know if this works though:
    PHP Code:
    this.addEventListener(Event.ENTER_FRAMEcheckFrames);

    function 
    checkFrames(e:Event):void
    {
       
    // if the frame is 20 AND secondMC is defined (else it will be one false and
       // the if statement will fail)
       
    if(this.currentFrame == 20 && secondMC)
       {
          
    // do your stuff
          // cleaning up to spare system resources
          
    this.removeEventListener(Event.ENTER_FRAMEcheckFrames);
       }

    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  5. #5
    I managed to fix my problem. What happened was that I didn't name my MCs so Flash couldn't detect 'em. I named my MC by going secondMC.name = 'secondMC_name'.
    ~~~~~jOn waZ hErE~~~~~

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center