A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] addChild to specific frame?

  1. #1
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801

    [RESOLVED] addChild to specific frame?

    I'm using script to replace some TextFields with instances of another class at runtime. Basically calling:
    Code:
    var par:DisplayObjectContainer = textfield.parent;
    var idx:int = par.getChildIndex(textfield);
    //remove tf from parent
    par.removeChildAt(idx);
    //add self in place!
    par.addChildAt(this, idx);
    In my code I'm also adding the textfield as a child of the new instance, but I'm pretty sure that doesn't matter to this issue. Also possibly important, the parent seems to be MainTimeline. The problem is that the new instances appear on all (subsequent?) frames, whereas the TextFields they replaced were only on a particular frame. Is there a way to preserve the frame association?

  2. #2
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    my guess would be ... and I'm new at this too ... try instantiating a new version of the same top-level class with each frame, named for the frame number, and then call it locally? I never work with frames so this is one I'm probably never going to get too good at...

  3. #3
    hippie hater Cimmerian's Avatar
    Join Date
    Oct 2006
    Location
    over there
    Posts
    599
    //add self in place!
    par.addChildAt(this, idx);
    ???
    If you can't explain it simply, you don't understand it well enough.
    Albert Einstein

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Quote Originally Posted by Cimmerian
    //add self in place!
    par.addChildAt(this, idx);
    ???
    I'm not sure what you're trying to say. This code is an excerpt from a class which extends MovieClip (called SelectableText in my code), and wraps a TextField to add behaviors to it. "this" in the code above refers to the new instance of that class, which is processing the TextField which it should wrap.

    Since writing my initial post, I have also discovered that not only do the new SelectableTexts appear in all frames, when returning from a different frame to the original frame, the original TextFields are back, each showing both in the SelectableText AND as it originally was. I think I'll have to do the conversion at authoring time using jsfl instead of at runtime, which seems to have too many side effects.

  5. #5
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,358
    As far as I know, this technique only worked for ActionScript 2. The process by which the timeline handles timeline-based instances has completely changed and, I'm pretty sure, is hidden from the user meaning there's no way to dynamically create an instance at runtime and associate it with another instance's timeline definition.

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