remove and check container #725
Replies: 1 comment 3 replies
-
You just need a reference to the let myScreen = new ASSETS.SwitchScreen(value);
application.add(myScreen);
application.remove(myScreen); But there are other ways to get references to content objects in a container you might prefer too. I wrote a summary in this comment of methods described in the Piu chapter of the book @phoddie and I wrote. It has a 6 page long section called "Accessing Content Objects in a Container". If you don't want to use application.add(new ASSETS.SwitchScreen(value, {name: "myScreen"}));
let myScreen = application.content("myScreen");
application.remove(myScreen); Here's what's happening in the code above:
It depends what you mean by visible ;)
let myScreen = new ASSETS.SwitchScreen(value);
let foo = myScreen.container; // foo is undefined because `myScreen` hasn't been added to the application
application.add(myScreen);
foo = myScreen.container; // foo is now a reference to the `application` object
application.remove(myScreen);
foo = myScreen.container; // foo is undefined again because it has been removed from the application
let myScreen = new ASSETS.SwitchScreen(value);
application.add(myScreen);
myScreen.visible = false;
let myScreen = new ASSETS.SwitchScreen(value, {left: 320});
application.add(myScreen); Checking whether a content object is within the bounds of the display might look something like this: let isPartiallyVisible = myScreen.x <= application.width;
let isFullyVisible = (myScreen.x + myScreen.width) <= application.width; |
Beta Was this translation helpful? Give feedback.
-
Good morning,
First my container was in my main.js. Then I move it in my assets.js
I add it in my main.is with
application.add(new ASSETS.SwitchScreen(value));
How can I remove it ?
PS: I can't use something like:
application.remove(application.first);
but I need something like:
application.remove(SwitchScreen);
How can I check if is it visible?
normally I used:
SwitchScreen.index
result = -1 if not visible
but now it doesn't work
Beta Was this translation helpful? Give feedback.
All reactions