How can I destroy a widget component in ue4 blueprints? - widget

I have a question regarding UE4 widget objects in blueprints. I try to spawn new widget objects at runtime and add them to a unit. Then I want to play a simple animation and destroy the created widget afterwards. However I don't know how to destroy a widget component.
If I try to simply remove from parent I get the following warning:
UWidget::RemoveFromParent() called on '/Engine/Transient.UnrealEdEngine_0:GameInfoInstance_C_0.DamageWidget_C_12' which has no UMG parent (if it was added directly to a native Slate widget via TakeWidget() then it must be removed explicitly rather than via RemoveFromParent())
I also don't want to use the same widget component (and set the new widget as the existing one) because it overwrites the existing widget component and cancels the animation if two widgets are spawned at nearly the same time(which I don't want).
How can I destroy my created widget component? I also don't want to just hide it because of memory issues.

Related

How to updating JLayeredPane while the JFrame is running ? java

Having read many tutorials, articles and questions, I am still have confusions about updating the GUI. Plus there are numerous related questions here on this website and still no luck - even though I think my problem is very simple.
Basically, I have a JFrame that has a JLayeredPane as its root container. And I have some layers of JPanels inside it.
The main issue is with updating a particular JPanel in this JLayeredPane. And for this particular Panel, I have implemented an update method that changes the contents inside it.
updatePanel(int para)
//doesn't remove this panel
//removes some existing labels and replaces it with new ones
Once I create the whole Frame, obviously just calling this method won't show any change displayed the frame.
private void static main (String[] args){
WindowFrame frame = new WindowFrame()//WindowFrame extends JFrame
frame.updatePanel(2);
.....
.....
}
And that's where I am stuck. I want to update the contents as the frame is displayed.
I saw these methods mentioned by people but due to nature of problems, I couldn't fully grasped the concepts. Plus the documentation on these methods isn't really helping - at least to me.
revalidate()
validate()
repaint()
How/when should these methods should be called? Or is this not the right way of what I should be doing, given these methods and the problem I am trying to solve?
Thank you for your time.
Basically you need two methods:
revalidate()
This method does the same as invalidate() but in AWT event dispatching thread (i will just call it Swing thread later on)). It updates container and all of its ancestors (parent containers in which this one is placed) layouting.
Basically if you either move something inside this container or place/remove components inside of it you should call this method (or invalidate in case you are performing it in Swing thread, for example inside any Mouse/Action listener body or just inside).
repaint()
This method forces component, all its sub-components (if it has them) and parent container (basically if this component is NOT opaque) to update what they are "painting".
Usually you don't need this method since all standard Swing components know when to repaint themselves and they do it on their own (that ofcourse depends on components UIs and some other things). This method might be useful in case you have your own specific components with some unique painting-way (for e.g. some custom selection over the components) and in some rare problematic cases with standard components.
Also the way this method acts depends on the components placement (due to some Swing painting optimizations) - if you have some massive repaints rolling you'd better optimize them to repaint only those parts (rects) that you actually need to repaint. For example if you change the component bounds inside any container the best choice is either to repaint its old bounds rect and new bounds rect OR repaint rect that contains both of those bounds, but not the whole container to avoid repainting uninvolved in the action components.
So, basically in your case after some changes with panels you should call revalidate on their container (or invalidate) followed by repaint (in case revalidate leaves some visual artefacts) again for the container.
Guess i didn't miss anything and i hope that now you know the basic meaning of those methods.
revalidate at the end of your update method like so .
updatePanel(int para){
.....
.....
this.revalidate(); //of course this refer to the panel
parent.revalidate(); // parent refer to the window
}

Adobe flex popup single instance

I need to create a flex popup which would be a single instance but we can make it visible and invisible whenver we want to display it. I am not sure we can implement this kind of functionality using createPopup or addpopup method. Instance must be one and need to update it every time some event happen and make it visible or invisible.
thanks
createPopUp requires a class name. All the internals of creating the popup are in that method. You won't be able to use createPopUp with an existing instance of a window. However, when you call createPopUp, the results you get will be the instance of the new popup you just created.
However, addPopUp does accept an instance of an already creating component. You'll want to proceed in one of a few ways:
1) if the popup instance exists; use addPopUp; otherwise use createPopUp:
if(myPopUp){
PopUpManager.addPopUp(myPopUp, etc...)
} else {
myPopUp = PopUpManager.createPopUp(this, myPopUpClassName, etc..);
}
2) Create the popup yourself and always use addPopUp
if(!myPopUp){
myPopUp = new myPopUpClass();
}
PopUpManager.addPopUp(myPopUp, etc...);
Whenever you want to hide the pop up, do so using the removePopUp() method. This method will not destroy the pop up instance, just remove it from view.
PopUpManager.removePopUp(myPopUp);
You're going to have to figure out how to store the reference to your popup outside of the PopUpManager.
And I warn you that all the code I wrote here is psuedo code.

Dojo, how destroy a custom widget?

I have created a custom dijit widget which contains a grid and some buttons.
What is the right way to destroy it? override uninitialize, destroy, destroyRecursive? which method and in which order?
Thanks.
Generally uninitialize is the best place to do this, since it is an extension point called within the destroy function before other teardown occurs.
That said, depending on how you are adding your child widgets, you may not actually have to do anything. For instance, if you are defining your child widgets within a template, widgets declared within a template automatically get added to an array which is iterated through in destroy.
If you wanted to be sure, for testing you could connect to the destroy methods of your child widgets to log a message when they get called.

How to make flash builder component affect main application?

I have my main application, which contains several instances of a component that create a grid of photos belonging to a certain category. (the grids, and the photos are created dynamically with a loop).
I'd like to be able to click a photo to run a function that loads the large version of the photo into a separate element that is contained in the main application. So I created a Photo component in my main application, but how, using actionscript, do I change the 'currentphoto' variable in my main application from inside the tileview component?
Alternately I could put the function in the main application (probably more logical in the long run), but how would I call it from the child component?
I would dispatch a Event.SELECT event in the tileview when a photo is selected that the main application adds an event listener for. The tileview should have a selectedImage property or something similar so that the main app can determine what image to load in the photo component when it receives an event.

IComponentActivator Instance

How can I use an IComponentActivator instance for a component, not just specifying a type.
That is, instead of
Component.For<XYZ>.Activator<MyComponentActivator>();
I want to be able say
Component.For<XYZ>.Activator(new MyComponentActivator(someImportantRuntimeInfo));
Also, is there a way I can choose an activator dynamically for a non specifically registered component? That is, I want to have an activator that looks at the type being resolved, decides if it can activate it, and if not, responsibility for activation should be passed on to the default activator.
So basically I want a global IComponentActivator that has the following logic:
Create(Type type){
if (ShouldActivate(type)){
DoActivate(type);
}
else{
// do default activation here somehow
}
}
Thanks!
EDIT
Just use ILazyComponentLoader
Activators are instantiated by the container, and there is no way to provide instances OOTB.
If you really want to do this, I'd say you can extend the container itself.
Put your custom instace activators in ExtendedProperties of your component under a well-known key
inherit from DefaultKernel
Override CreateComponentActivator method
In there return the activator from ExtendedProperties of the component
There's no way to create global activator. You can add IContributeComponentModelCreation implementation that switches the activator to some custom one wen creating your component if you really want to.
But the most important question is this:
What are you trying to achieve by
this? Why do you want to do this in
the first place?