AddChild and removeChild (AS 3)

Hi
If I load an external swf (located in the same dir as the one
loading it) with addChild. It looks something like this
var url:String = "patfinder_extra1.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
addChild(ldr);
Now, I want to be able to close/remove this new child within
itself, image a little close button with the label "I'm a child and
will close my self if i click here!".
Now, this removeChild is a mystery and the new restrictions
in paths in AS 3 really makes it hard. To simply use
this.removeChild() returns errors.
Any tips of how to close this thingy?
:)

you can use the code below to have the child movieclip remove
itself from its parent's display list, but that won't clear it for
garbage collection.
i would have the child call a function in the parent that
removes it and nulls all references to its loader so it can be
garage collected.

Similar Messages

  • AddChild and removeChild with MouseEvent

    Hello, I am a newby at AS3. I need help with addChild and removeChild.
    I want to make a two buttons one addChild and other removeChild . Friend helped me a little bit, but I didnt uderstand the script ;]
    Here is the example script which my friend gave to me. In other words I want to make a button that attached hair and the other that removes.
    Should I make a separete custom class for Hair? And if do, can someone help? :]
    ActionScript Code:
    public function changeHairs (newHair: Hair): Hair
    Face.removeChild (oldHairs);
    oldHairs = newHair;
    Face.addChild (newHair);
    newHair return;
    Or modify this code. I know how to change text, but dont know how to change objects
    ActionScript Code:
    package  {
        import flash.display.MovieClip;
        import Button;
        import flash.text.TextField;
        import flash.events.MouseEvent;
        public class Faces2 extends MovieClip
            public var arr:Array = new Array("a1","a2","a3");
            trace("aab");
            public var txt:TextField = new TextField()
            public var btnBack:Button = new Button();
            public var btnFwd:Button = new Button();
            public var arrPos:Number = 0;
            public function Faces2()
                setupInterface();
                setupData(arrPos);
            public function setupInterface():void
                btnBack.x = 100; btnBack.y = 10;
                btnFwd.x = 200; btnFwd.y = 10;
                btnBack.addEventListener(MouseEvent.CLICK, back);
                btnFwd.addEventListener(MouseEvent.CLICK, fwd);
                addChild(btnBack);
                addChild(btnFwd);
                txt.textColor = 0xFF0000;
                txt.width = 300;
                txt.border = true;
                txt.x = 100; txt.y = 100;
                addChild(txt)
            public function fwd(evt:MouseEvent):void
                arrPos ++;
                if(arrPos >= arr.length)
                    arrPos = 0;
                setupData(arrPos);
            public function back(evt:MouseEvent):void
                arrPos --;
                if(arrPos < 0)
                    arrPos = arr.length - 1;
                setupData(arrPos);
            public function setupData(pos:Number):void
                txt.text = arr[pos];
    P.S. sorry for my bad english

    did you create your hair movieclip and assign it a class?

  • Action script 3 question: addChild and removeChild on same button??

    I'm trying to make a button that when u click once, the movieclip will be removed and second time back on stage and so forth....
    somehow i get this error
    ==================================
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
    at flash.display:DisplayObjectContainer/removeChild()
    at sample_fla::MainTimeline/btnClick()
    ==================================
    Anyone can help me with this, since I'm doing an interactive web for client and the deadline is near..... thanks in advance.
    these are my code:
    stop();
    var swf:MovieClip;
    var loader:Loader= new Loader();
    var defaultswf:URLRequest= new URLRequest("./newSwfImport.swf");
    //default swf when loaded
    loader.load(defaultswf);
    //add to stage
    allSwfLoadHere.addChild(loader);
    var boolean:Boolean = true ;
    function btnClick(event:MouseEvent):void {
    if(boolean == true){
    allSwfLoadHere.removeChild(loader);
    boolean == false
    if(boolean ==false){
    allSwfLoadHere.addChild(loader);
    boolean == true
    newSwfImport.addEventListener(MouseEvent.CLICK,btnClick);

    you have, at least, two errors:
    1.  you failed to use an if-else and
    2.  when trying to re-assign your boolean, you tested.  ie, you used == when you should use =.  so, your boolean remains true.  then when you execute the 2nd time, you try and remove something that's already been removed.
    use:
    var swf:MovieClip;
    var loader:Loader= new Loader();
    var defaultswf:URLRequest= new URLRequest("./newSwfImport.swf");
    //default swf when loaded
    loader.load(defaultswf);
    //add to stage
    allSwfLoadHere.addChild(loader);
    var boolean:Boolean = true ;
    function btnClick(event:MouseEvent):void {
    if(boolean){
    allSwfLoadHere.removeChild(loader);
    } else {
    allSwfLoadHere.addChild(loader);
    boolean=!boolean;
    newSwfImport.addEventListener(MouseEvent.CLICK,btnClick);

  • Loading .swf, addChild, and removeChild

    Hello all,
    I'm trying load an swf when you click a button, and load another in it's place when you click a different button.   I'm using addChild to insert the swf onto the stage.  Problem is that every time I click a new button, the new swf is loaded on top of the previous one, and I need the previous one to disappear.  I tried using the removeChild method before the new swf is loaded to no effect.
    Here's the function I'm using for the loader with my removeChild attempt in bold:
    function newPage():void {
        trace("load activated");
        trace(""+target+".swf");
        var req:URLRequest=new URLRequest(""+target+""+".swf");
        var loader:Loader = new Loader();
       if (loaderState==true){
            top_mc.removeChild(loader);
        loader.load(req);
        loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preLoad);
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
        function preLoad(event:ProgressEvent):void {
            var percent:Number=Math.round(event.bytesLoaded/event.bytesTotal*100);
            top_mc.preload_txt.text=String(""+percent+"");
        function fileLoaded(event:Event):void {
            trace("file loaded");
            top_mc.addChild(loader);
            loaderState=true;
    The error I get is as follows:
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
        at flash.display::DisplayObjectContainer/removeChild()
        at main_fla::MainTimeline/newPage()
        at main_fla::MainTimeline/workLoaderEnter()
        at main_fla::MainTimeline/clickF()
    Perhaps there is a way to give the addChild an instance name so that I can remove it later?
    Any ideas?
    Thanks!

    Part of the problem is your trying to remove the loader just after you define it...  it is not a child of anything at that point.  Try the following instead of what you have.   Another problem you can avoid is to not nest functions...
    var loader:Loader
    var loaderState:Boolean = false;
    function newPage():void {
    if (loaderState){
            top_mc.removeChild(loader);
        var req:URLRequest=new URLRequest(""+target+""+".swf");
        loader = new Loader();
        loader.load(req);
        loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, preLoad);
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
    function preLoad(event:ProgressEvent):void {
        var percent:Number=Math.round(event.bytesLoaded/event.bytesTotal*100);
        top_mc.preload_txt.text=String(""+percent+"");
    function fileLoaded(event:Event):void {
        top_mc.addChild(loader);
        loaderState=true;

  • Explanation of addChild and removeChild?

    Hi
    I'm having trouble getting my head around using removeChild.
    For example, I have a function that is triggered by a button click.  This function loads an external swf.  I then set a global variable swfLoaded to true, with the idea of having an if condition that executes removeChild(loader) if swfLoaded is true.
    When trying to execute removeChild(loader), I get an error telling me that it must be the child of the caller.
    I've seen the code below, which loads a default swf, but I don't want a default swf - I just want one loaded if the button is clicked, and then if another button is clicked, the original one to be removed before the next swf is loaded.
    Can someone please explain to me why removeChild(loader) only works if addChild(loader) was originally executed outside of the function (like below)?
    How do I make this code work without loading a default swf, just loading one once someone clicks a button, and then removing it?
    var Xpos:Number = 110;
    var Ypos:Number = 180;
    var swf:MovieClip;
    var loader:Loader = new Loader();
    var defaultSWF:URLRequest = new URLRequest("swfs/eyesClosed.swf");
    loader.load(defaultSWF);
    loader.x = Xpos;
    loader.y = Ypos;
    addChild(loader);
    // Btns Universal function
    function btnClick(event:MouseEvent):void {
    removeChild(loader);
    var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
    loader.load(newSWFRequest);
    loader.x = Xpos;
    loader.y = Ypos;
    addChild(loader);
    // Btn listeners
    eyesClosed.addEventListener(MouseEvent.CLICK, btnClick);
    stingray.addEventListener(MouseEvent.CLICK, btnClick);
    demon.addEventListener(MouseEvent.CLICK, btnClick);
    strongman.addEventListener(MouseEvent.CLICK, btnClick);
    Cheers
    Shaun

    Oh, I just did not pay enough attention to your code.
    The way you wrote it - you don' have to remove it every time. A better approach is to add it only once and in subsequent calls to unload it:
    var loader:Loader = new Loader();
    // add it once
    addChild(loader);
    function btnClick(event:MouseEvent):void {
         // don't need this
         //removeChild(loader);
         // unload previously loaded content
         loader.unload();
         var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf");
         loader.load(newSWFRequest);
         loader.x = Xpos;
         loader.y = Ypos;
         // don't need this either
         // addChild(loader);
    Also, in Flash 10 it is better to use loader.unloadAndStop()

  • Difference between addChild and internal movieclip

    Hi all,
    What is the difference bettween addChild and the movieclip which is in the movieclip.
    we can get those instance from getChildAt() but
    as per the internal movieclip we can get instance from "mc.mcInternal".
    But when i addChild in "mc" we unable to get that instance from this method "mc.mcInternal".
    what is the diffecenct between addChild and internal movieclip.
    Thanks in Advance
    flashgeeks.

    When you create child movieclips inside a parent movieclip, Flash Pro automatically declares member variables for them, so you can access them by "mc.mcInternal". If you add child to a movieclip at runtime, member variables are no longer declared automatically.
    You either declare member variable yourself (public var myMc:MovieClip;) or you can always access it by myParentMc.getChildByName("myChildMcName");
    Otherwise, there's no difference between the two. Only one more thing to keep in mind: If you put movieclip into another movieclip, you control its z-orderby its layer. When you add child by addChild() method, children are put into "depths", not layers anymore. The lowest depth is just above the highest layer. If you want to addChild() to a specific layer, you have to create an empty movieClip (a holder) in Flash Pro, put it in desired layer and then call myHolder.addChild(childMc).

  • Problem with addChild() and getChildAt()

    Can someone tell me why the last trace outputs undefined?
    var myMC1:MovieClip = new MovieClip();
    var myMC2:MovieClip = new MovieClip();
    myMC1.addChild(myMC2);
    myMC1.getChildAt(0).name = "myMC3";
    trace(myMC1.getChildAt(0)); // outputs [object MovieClip]
    trace(myMC1.getChildAt(0).name); //outputs myMC3
    trace(myMC1.myMC3); // outputs undefined

    quote:
    Originally posted by:
    smohadjer
    So if I understand you correctly if I add a movie clip to
    another movie clip using addChild() it would not be the same and I
    won't be able to use the dot syntax to refer to the second movie
    clip. But why?
    This is because when you use addChild you add it to
    DisplayContainer display list - not as a property of the parent
    movie. Dot notation is for reading or invoking something that is in
    the scope of an object. By adding a display object to display list
    - it doesn't add another property to the Object's scope. Again, as
    Ned said there are way to read the content of display list. In
    order for the syntax you are craving for to work you need to create
    properties and methods explicitly. Most of the classes in the
    flash.display package are not dynamic (you cannot add more than
    they already provide - you need to extend them in order to do
    that),
    This is the way it is. I hear what you are saying though (and
    must admit that, perhaps, it looks more intuitive to refer to
    children via dot notation) but from the viewpoint of OOP and AS3
    architecture it would not be correct. I do see a good reason for
    Adobe decoupling display list from object's properties. But this is
    too long a discussion.

  • Error #2025: addChaild and removeChild

    hello all
    I have the app but I got a problem
    ArgumentError: Error # 2025: The supplied DisplayObject must be a child of the caller.
    at flash.display :: DisplayObjectContainer / removeChild ()
    at xxxxx_fla :: MainTimeline / hitPoint ()
    my code
    import flash.events.Event;
    import flash.events.MouseEvent;
    var pencilta:Shape = new Shape();
    var activeColor:uint = 0x000000;
    var aaa:a = new a();
    aaa.x = 0;
    aaa.y = 0;
    addChild(aaa);
    var bbb:c1 = new c1();
    bbb.x = 308;
    bbb.y = 108;
    addChild(bbb);
    var ccc:c2 =new c2();
    ccc.x = 265;
    ccc.y = 175;
    addChild(ccc);
    var ddd:c2 = new c2();
    ddd.x = 235;
    ddd.y = 260;
    var eee:c2 =new c2();
    eee.x = 200;
    eee.y = 355;
    bbb.addEventListener(MouseEvent.MOUSE_DOWN, hta1drag);
    bbb.addEventListener(MouseEvent.MOUSE_UP, hta1drop);
    bbb.addEventListener(Event.ENTER_FRAME, hitPoint);
    function drawingta()
              addChild(pencilta);
              pencilta.graphics.lineStyle(10, activeColor);
    function drawPencilta(e:MouseEvent):void
              pencilta.graphics.lineTo(bbb.x, bbb.y);
              e.updateAfterEvent();
    function hta1drag(e:MouseEvent):void
              e.target.startDrag();
              pencilta.graphics.moveTo(bbb.x, bbb.y);
              stage.addEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);
              drawingta();
    function hta1drop(e:MouseEvent):void
              stopDrag();
              stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);
    function hitPoint(e:Event)
              if(bbb.hitTestPoint(ccc.x,ccc.y, true))
                        removeChild(ccc);
                        addChild(ddd);
              else if (bbb.hitTestPoint(ddd.x,ddd.y,true))
                        removeChild(ddd);
                        addChild(eee);
              else
                        trace ('mbuh lah');
    thank's

    use:
    import flash.events.Event;
    import flash.events.MouseEvent;
    var pencilta:Shape = new Shape();
    var activeColor:uint = 0x000000;
    var aaa:a = new a();
    aaa.x = 0;
    aaa.y = 0;
    addChild(aaa);
    var bbb:c1 = new c1();
    bbb.x = 308;
    bbb.y = 108;
    addChild(bbb);
    var ccc:c2 =new c2();
    ccc.x = 265;
    ccc.y = 175;
    addChild(ccc);
    var ddd:c2 = new c2();
    ddd.x = 235;
    ddd.y = 260;
    var eee:c2 =new c2();
    eee.x = 200;
    eee.y = 355;
    bbb.addEventListener(MouseEvent.MOUSE_DOWN, hta1drag);
    bbb.addEventListener(MouseEvent.MOUSE_UP, hta1drop);
    bbb.addEventListener(Event.ENTER_FRAME, hitPoint);
    function drawingta()
              addChild(pencilta);
              pencilta.graphics.lineStyle(10, activeColor);
    function drawPencilta(e:MouseEvent):void
              pencilta.graphics.lineTo(bbb.x, bbb.y);
              e.updateAfterEvent();
    function hta1drag(e:MouseEvent):void
              e.target.startDrag();
              pencilta.graphics.moveTo(bbb.x, bbb.y);
              stage.addEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);
              drawingta();
    function hta1drop(e:MouseEvent):void
              stopDrag();
              stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawPencilta);
    function hitPoint(e:Event)
              if(bbb.hitTestPoint(ccc.x,ccc.y, true))
    if(ccc.stage){
                        ccc.parent.removeChild(ccc);
    // ccc=null; ??
                        addChild(ddd);
              else if (bbb.hitTestPoint(ddd.x,ddd.y,true))
    if(ddd.stage){
                        ddd.parent.removeChild(ddd);
    // ddd = null; ??
                        addChild(eee);
              else
                        trace ('mbuh lah');
    thank's

  • MovieClip, addChild and Position

    Hi!! I'm having a problem with a MovieClip...
    I have 2 different MovieClips... that I'm putting into another MC (mc3)..... the new MC's position is x=0 y=0.... I assume this is default....
    what I'm trying to do is change the position of my MC.... but I want the other 2 movies inside (mc and mc2) to be on x=0 and y=0 inside the new movieclip....
    I hope it's not too confusing.... I'm doing this because I'm trying to save the movie as a jpg.... and the only way i can see the file complete is when I set the size of all the stage (1024 x 768).... I only want to save the mc3....
    here's my code.... hope you can help me
    var mc3:MovieClip=new MovieClip();
    addChild(mc3)
    mc3.addChild(mc)
    mc3.addChild(mc2)
    mc3.x=292;
    mc3.y=126;
    //this is what's happening when i save the file

    Thanks but no, that's not doing anything.... it's moving the contents....
    what I'm doing is a game of drag and drop, where children can choose an undefined number of houses and buildings, and arrange them over a city... that's done.... the background and houses are inside mc and the buidings are inside mc2.... I'm working  like that 'cause I must be able to erase everything on each step of the way... erase houses.... then erase buildings..... finally, when everything is over, I have to be able to save the map with the houses and buildings as a jpg file... and also I have to be able to print the map..... that's why I put both mcs inside a new one (mc3) to deal with only one movieclip............  the print part is going fine.... but I can't make the jpg to be just the map.... in order to see the map complete I have to save the file with a size of 1024 x 768... and the idea is to save a jpg with just the map......
    so I was wondering if there is a way to change the position of the movieclips inside my new movieclip.... or any other way I can fix this....
    thanks!!!

  • HTML5 Canvas: addChild and position

    Hey Guys
    I have an item on the stage called 'square1', I have added a symbol from the library and given it the name 'circle1'.
    I wish to position circle1 at the exact location of square1, my question is - how would I go about doing that?
    Thanks

    Knowing JavaScript is going to be essential for you to use Canvas. If you really don't want to get your hands into the code you should do your best with the timeline.
    If you're ready to take the canvas plunge then JavaScript has to become a tool for you. The second page of what I linked would show you that for almost every bit of ActionScript you might be used to, there's a translation over to JavaScript that's necessary. So every time you go to do something you're going to be right back here.
    The best option just might be for you to take a look at EaselJS. There's lots of very simple demos that can get you started with HTML5/Canvas and will give you answers you want in Flash. Take a look:
    CreateJS | A suite of Javascript libraries and tools designed for working with HTML5

  • AddChild or visible property

    Hello,
    I am brand new to flash and I have been reading lots of tutorials and help forums.  I am to the point now where I am working on my own project and this is the best way for me to pick it up is to get down and dirty.
    So far so good but I have a question, more like a poll.
    I have 80 symbols that at any given time, 10 of them will be turned off and then some animation in their place.  What is the best way to acheive to constant on and off of these symbols.  Should I use an addChild and removeChild in AS3 or drag them to their stage points and use a a visible and hid property in the actionscript?  The locations of the 80 symbols never change, just their visiblity.  Excactly the same with the replacement animation.
    Thanks.  I am curious to see your answers!

    just change their visibility, it's the easiest way.

  • Can I use the debugger to identify items on stage?

    Hi all,
    I have an app that uses several Loader objects to load extenral swf files.  Things go well except for one point.  I have a quiz element that's loaded through a loader named 'quiz'.  When the quiz is done, I remove the quiz element with removeChild(quiz).  The quiz disappears from the screen every time except for one question.  I can't identify what's going on differently for that question.  I've debugged this and can see that my quiz object is set to null, but I can plainly see the quiz still onscreen.
    To further confuse me, I use the same loader object multiple times through the app, and just add it and remove it from the display list with addChild and removeChild.  When my one problem question comes up and fails to go away, the app continues to the next question, and I can see that there are now 2 quiz objects stacked on top of each other.  I have no idea how this can happen when I'm using the same loader object for all the questions.
    Anyway, I'm hoping I can use the variables in the debugger to identify what I'm seeing onstage, but am not sure where to start looking.  Are all dispaly objects that are children of the app within the stage in the debugger variables?  The root?  I'm just not sure where to look.  If someone can tell me where to find the display objects on the stage or whatever in the debugger variables, that would be great and I can hopefully troubleshoot it from there.

    here's some code that might help . . . they're really pretty simple.
    Here are the 2 main methods that handles loading and unloading the quiz.
            public function put_question():void{ // BUILD LOADER TO LOAD QUIZ SWF
                quiz = new Loader(); // QUIZ IS A CLASS VARIABLE
                addChild(quiz);
                quiz.load(new URLRequest("quiz.swf"));
            public function quiz_done():void{
                removeChild(quiz);
                ethics_content.nextScene(); // ETHICS_CONTENT IS A CLASS VAR LOADER THAT WAS ADDED TO THE STAGE
    put_question is called from the timeline at the end of an animation.  The method executes and puts the quiz.  The quiz_done method is run when the user selects the right anwser, reads some feedback, then clicks to continue.
    I have 5 scenes before the problem point that use these methods and the work great.  The quiz appears, works fine, then disappears when the quiz_done function is called.  In the last scene, though, the quiz just doesn't disappear when the quiz_done function runs!
    I'm hoping I can find a way to use the debugger to set a break point at the end of the quiz_done method and then go through the display list and see what it is I'm still seeing, as the quiz should be removed from the display list at that point.

  • Modeling state transitions between screens

    Hi,
    I'm trying to build a flex application that is made of 20 or
    so screens. Some of these screens are serially connected, much in a
    wizard manner, but many others are not.
    I have not found a language construct yet that would allow me
    to model these screens as states and that would allow me to trigger
    event-based transitions.
    It sounds exactly like what States do, right? But the actions
    within a State are all about "addChild" and "removeChild" and it
    seems awkward to define all the UI components in this additive
    manner.
    Isn't it possible to define a container for each screen and
    then simply move from one to another container based on button
    presses?
    This sounds like what viewStacks do, right? But viewstacks
    seem to load all at the same time, don't seem ideal either.
    So I'm looking for a best practice pattern for this. I'm
    having a hard time believing that all the flex applications can fit
    in one screen with accordions, tabbars and similar.
    Thanks for a great article series! FIG is the best I've read
    so far, and it's spot on... designers need to learn a new visual
    language.

    Seems like the ViewStack component might be what you are
    looking for... simple to use, and you can attach transition
    effects. There is a good example in the Flex developer's guide (
    http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Live Docs_Book_Parts&file=navigators_066_03.html),
    showing transitions triggered by a LinkBar... but you can also
    change the view in code by setting the selectedIndex
    property.

  • Air 3.0 beta2 -GPU auto disposing textures to quickly on android?

    game example:
    a sprite is filled with a texture rocks.png
    In Air 2.7 and below, once one of these sprites are first added to the display list a quick stutter happens as it writes to the GPU. I can now add and remove others fast with no blips/hickups as i believe it would always keep that texture (rocks.png) stored on GPU.(no explicit cache as bitmap called).
    now with Air 3.0 if that texture is not on the display list it appears to be removed from the GPU rather quickly, because i may get stuttering/appearing late when i add them to the display list again. All other versions of Air it was always instant (after the first one was added to the display list).
    (All objects are pooled, i am only calling addChild and removeChild)
    if i leave some instance of this rocks.png texture on the display list, the whole game runs fine again... I believe its because it never dumps from the GPU
    I am using Air 3.0 beta 2 SDK which was released last week, and have packaged and Android App using the captive runtime.
    ...so is there some newer garbage collection dumping the gpu mem quicker if its not in use or something?
    thanks

    Hi bjsr12345,
    That was quite a long time back. Unfortunately, even today, if your target platform is below ICS (Android 4), that rear camera orientation issue is still present. You can adjust so that you flip the video object within your app if it's upside down (say, when you are recording a video and allowing the user to change between front and rear cams mid-stream), but there is no way to change the orientation of the video itself, sans adding some lines of code in a native Android code itself, not through Air. Hope this helps.
    Alex

  • Tab nevigator in flex

    hi,
    i want to add and remove the tab pans according the
    different user group
    for that i am using addchild(); and removechild(); to add and
    remove the tabs
    but i am able to remove the child only and not to add the
    child any one pls help me to tackle this problem

    I believe there is an ensureCellIsVisible method.

Maybe you are looking for