I try to change the scene hierarchy. The appendChild method work but the attachedCallback and detachedCallback are called too. I want just perform the appendChild's native code only.
How can i do it?
You cannot really for A-Frame's custom elements. The callbacks are critical. Maybe you can monkeypatch or inherit the prototypes (e.g., AFRAME.AEntity.prototype)? But heavily, heavily not recommended and strange.
Related
In JavaFX, once I have a Scene, Pane, and/or Canvas setup and have my Node graph setup, how do I add my own custom components? I've already added them to the Node graph, but they're not being rendered, because they neither inherit from a particular node nor implement the particular method necessary to have their rendering method called. There isn't much complexity involved in drawing these components -- it's about twenty calls of drawRectangle etc..
If I recall correctly, in Swing, I had each component implement a version of draw, and draw was called automatically as part of the framework. But I haven't found the equivalent mechanism in JavaFX yet.
JavaFX doesn't have "ondraw" in the usual sense, because components are usually composed and rendered on GPU.
There are multiple ways to create custom drawing, depending on your needs and requirements.
You can merely use Canvas for simple drawing, pretty clear described in official tutorial . This is the simplest way for complex drawings and probably it is what you are looking for. Add canvas node to the scene and draw on it. You can encapsulate the logic by extending Canvas or a container component that will contain Canvas (or by presenter etc. if you employ some kind of MVP/MVC).
Another way is just to compose from existing visual components e.g. shapes and images, for example by extending or preparing a Pane or other container and adding children components.
Yet another is to prepare a bitmap with custom drawing and use Image component, you can use Swing or other APIs to draw a bitmap in advance and use it for rendering. In general this is similar to using canvas but more complex, unless you see clear benefits or have particular reasons, canvas is preferred.
Last way is to implement custom scene Node with complete rendering, I would not go into detail and advice against it; it is relatively complex, will use non-public APIs, probably would not be compatible between JDK releases and is useful only for very special needs.
Note, if you are creating a custom reusable library component, you probably will need to dive into the topic of skinning and component lifecycle.
I needed to pass in the Pane that I'm using for drawing into the constructor of my "custom class." The custom class then adds the necessary shapes to the provided pane. I assume I'll also need to keep track of those shapes as a data member of the custom class and remove/replace them when the custom class needs a new visual representation.
See Fedor Losev's answer below for a more complete list of options. E.g., I could have used a Canvas instead of a Pane.
Hey guys!
We used to write our UnitTests with FlexUnit and we were just testing our model. Now we want to test the view too. Before i run my tests i create an instance of my view and my model to test the stuff. When i try to access the view i get a null pointer exception. If i add the view to the displaylist it somehow works - even if i remove it from the list right after adding.
it looks something like this:
var myView: MyView = new myView();
//myView.initialize(); will throw error
Application.application.addChild(view);
Application.application.removeChild(view);
myView.initialize(); // will work
Hope you can give me a hint.
Sims
Flex UIComponents do not walk through the component lifecycle until after they are added to a container. As such, variables may not be initialized and children may not be created if you never add it to a container.
More info on the Flex Component LifeCycle. You'll notice there are 11 steps after the component is added to the container.
I suspect that adding it, then removing it, could cause other issues but it depends what you're trying to test.
To know your exact error, we'd have to see what code is in the initialize method on the view. Most likely it accesses a child that was not created yet.
MXML components will often masks the lifecycle steps, but a component will still go through them.
I hope this helps; but since you didn't ask a question I'm not sure if that was the information you were after.
In addition to what (www.Flextras.com) wrote, which I was just about to post as well, you might consider a different approach to testing your views.
First, consider a separation pattern like Presentation Model, MVP or MVC. They allow you to separate your view from your view behavior and test the behavior separate from the view. An approach like this, when done correctly, will take you a long way because you minimize or eliminate the AS3 code in your view.
If you really want to test your views, I would suggest that you use a functional testing tool for this. Unit test frameworks are good for testing classes in isolation. Once you start talking about views, which have complicated lifecycles, a functional testing framework starts to make sense.
Look at FlexMonkey as an example of a functional UI testing framework for Flex.
I recommend you to use User Interface Facade described here or here. This functionality is designed specially for UI componets testing.
I'm wondering what the best tool is for developing a mobile UI is. My requirements are that I retain full control over the look and movement of every UI component. I think Flex might be the best way to do this but I can't tell if I'll have that level of control using their UI components.
Any links would be appreciated. Thanks!
Edit: For example, looking at the documentation I see there's a an 'enabled' field which dims the color of a container and it's children if false. Am I able to change that so, maybe a repeated bitmap pattern appears if false?
Or, if there's a sliding menu can I edit the speed and change in speed as it closes?
You can create any component you like and make it look like anything you want. You don't have to use standard components. You can reskin any components just by specifying a new skin. It's really pretty easy.
You can create custom skins for Flex, for both Spark and Halo components. You also can create custom components, either based on other existing components, or based on the base component. You could even create custom objects which are just based on Sprites or similar (if you like to have control over everything :P).
edit
In response to your updated question. Regarding the enabled/disabled property, yes, it is possible to skin that. Spark components have states, for example a Button has a up, over and down state – and an disabled state. That state is exactly what is active when the enabled property is set to false. So yes, you can skin that.
Regarding the sliding menu animation, I'm not totally sure if that would be easily possible as I believe that this is coded into the component itself and not part of the skin to decide. However even if that is the case, you could instead create your own component that basically features exactly the same functionality but has a changed animation there.
I'm not sure if the Spark skinning wouldn't be able to do this though, because what you definitely can do is creating transitions between states. So if the slide is made with different states, you'll probably be able to change the transition as well.
Hmmm... I'm working at creating an AS3 UI library, since most of the ones out there each seem to miss out at least 1 feature I need. In order to keep it lightweight, I created everything from scratch. I use Sprites to render just about anything. But I want to allow the user of the library the possibility of adding a custom graphic for a button. Now... maybe that graphic is a MovieClip which has a nice animation within it.
So can I say sprite.addChild(mc) and then if I do mc.play, will the mc play within a sprite?
Thank you ::- ).
Yes.
Sprite extends DisplayObjectContainer which can contain any DisplayObject or subclass of DisplayObject.
I am going to write a simple layout system for a game GUI. I thought about the various layout systems used in GUI, such as absolute positioning, Java’s layout managers, springs and struts and the like. In the end I found out that I prefer the layout as viewed by CSS – padding, margin, floats, blocks, inlines, etc. Have you ever seen an application GUI done like this? Not a web application, but a “real” application where the CSS layout system must have been written from scratch. Do you think it possible to get a working and expressive CSS-like layout system, even if very simple, with a decent amount of code?
Update: I do not want to create the GUI from an external stylesheet. I would be happy with a runtime interface, ie. something like this:
Widget *container = [Container withWidth:100 height:100];
Widget *button1 = [Button withText:#"Foo"];
Widget *button2 = [Button withText:#"Bar"];
button1.floating = button2.floating = YES;
[container addObjects: button1, button2, nil];
Should have said that earlier, sorry.
I'm not sure if this would really be the best way to do it but I don't see any problems that would stop you from doing it.
You would need a CSS Parser of some kind to actually create the GUI from the stylesheet but I guess thats doable. There already are a bunch of CSS Parsers out there which you would probably just have to costumize a little as to fit your specific needs for the GUI.
I've done this in the past, and it's really only doable if you don't implement the CSS spec to the letter and just implement the stuff that you need. What I ended up doing was implementing a CSS parser, the selector statements and the cascading rules. The properties and the layout model were completely different because that simply wasn't needed at that time. I'd say that that also would've been where the bulk of the work of writing a full CSS engine would've been.
What I've done instead was create something that mimics the way HTML tables work because they are conceptually easy to work with and because the application itself was impartial to the whole "semantic web" discussion.
I couldn't find a lot of helpful resources on this, except for the CSS spec itself, because it contains the flex and bison syntax rules already.
Edit: in that case, you might want to look at how WebKit and Mozilla have implemented their layout engines as a reference.
No, I have never seen an application be designed around CSS's naming scheme.
Yes, I think it is entirely possible to create such a system, programmers are able to programmatically move buttons and other fields around. Generally using the default functions and parameters that exist for the widgets, if you were to use those widgets and just derived from them you would be able to accomplish what you wanted.
I am unsure as to why you would like to do this, but the answer is yes it is possible!