Save the form in a member variable instead of a local variable:
private var form:Form;
form = new Form();
Then, when you call addChild(homePage)
, also call removeChild(form)
.
removeChild(form);
var homePage = new HomePage();
addChild(homePage);
Alternatively, you might consider using the StackNavigator
component because it appears to me that you are creating an app with several pages, and this component is designed for handling navigation between pages, including saving the history so that you can go back and forward.