tags:

views:

33

answers:

1

Ok so I have a component, that has a function to remove itself as a popUp in its current Window, and add itself to a newly created Window.

It works, however, if the component has a child like a ComboBox, the drop down still pops up in the old window where it used to be, also scrollbars, and focus seems to behave incorrectly in the new window also.

It seems to me like Flex still thinks the component is a child of the original window, not the new window. I have no idea how to resolve this though.

Here is my code:

private var ownWindow:Window;
private var _inOwnWindow:Boolean;
private var _removedEffect:Move;
private var _openX:Number;
private var _openY:Number;

public function launchInNewWindow(e:Event):void
{
    _openX = Application.application.nativeWindow.x + this.x + 5; //keep in same spot add 5 for systemChrom border
    _openY = Application.application.nativeWindow.y + this.y + 30;//keep in same spot add 30 for systemChrom title

    this.parent.removeChild(this);
    ownWindow = new Window();
    ownWindow.systemChrome = 'none';
    ownWindow.type = NativeWindowType.LIGHTWEIGHT;
    ownWindow.transparent = true;
    ownWindow.setStyle('showFlexChrome', false);
    ownWindow.width = this.width > 750 ? 750 : this.width;
    ownWindow.height = this.height > 550 ? 550 : this.height;
    edit.enabled = false;

    _removedEffect = this.getStyle('removedEffect') as Move;
    if(_removedEffect == null)
    {
        openNewWindow();
    }
    else
    {
    // Wait for removed effect to play before adding to new window
_removedEffect.addEventListener(EffectEvent.EFFECT_END,delayOpenInNewWindow);
    }
}

private function delayOpenInNewWindow(e:Event = null):void
{
    var t:Timer = new Timer(100,1);
    t.addEventListener(TimerEvent.TIMER,openNewWindow);
    t.start();
}

private function openNewWindow(e:Event = null):void
{
    ownWindow.addChild(this);
    ownWindow.width += 5; //add to show dropshadow
    ownWindow.height += 10; //add to show dropshadow
    ownWindow.open();
    _inOwnWindow = true;
    ownWindow.nativeWindow.x = _openX;
    ownWindow.nativeWindow.y = _openY;
}

Any ideas?

Thanks!!

+1  A: 

Before I give this a run, have you tried a callLater on the openNewWindow() line?

[ lame fix attempt, i know -- but given that there doesn't seem to be an event that you can listen for in the case that the removedEffect isn't null and it seems like a timer is your only option there, I think it's o.k. to give lame fix attempts :-) ]

jeremym
I did what you suggested, this works as replacement to using the timer, so I no longer have to use a timer, however it still has the same issues. I think its a focus issue, for example if there are 2 texts fields, and I hit "tab" the second text fields highlights like it has focus, but I am still typing in the first one. Its very strange. I am guessing the problem is somewhere in the fact the same class is creating the new Window itself that it is adding itself too. The problem occurs whether it has a removedEffect or not.
John Isaacks
Is there a reason you NEED to use the exact same instance of the component? You could use a "clone-like" function that gets all the properties that you'd like to be copied to the new Window... have it be a static function that takes an instance of the current component, and in the end, call a public, internal 'destroy' function, that removesChild and removes all event listeners to prep the thing for being garbage collected. The reason I suggest this: even if you get everything working, there are certainly other problems that you'll get later on down the road that you don't anticipate.
jeremym
@jeremy, that sounds like a good idea, I will look into this, if I get it to work I will mark your answer accepted. Also +1 for giving me a solution that (doesn't fix my current question but) makes it possible for me to stop using a timer to delay calling a method.
John Isaacks