Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > General > Best Practices

Reply
 
Thread Tools Rate Thread Display Modes
Old 11-11-2008, 12:22 PM   #1
rawmantick
Pipty rupees only!
 
rawmantick's Avatar
 
Join Date: Jul 2007
Location: Novosibirsk, Russia
Posts: 1,713
Default Keeping best control overnon-child children of Flex component

Hi guys. Sory if this one belongs to Flex thread, but I decided to post it here.

I meet the problem of extending flex components very often. And as often I put non-children element (skins, decorations, some controls) onto my component. But in most situations I want all those decorations to be under usual children of a component.

I can create decorations (let's always call'em so in the thread) inside createChildren() method. This one will make all the decoration to be under children obviously. But classes (style properties), that my decorations are instances of, can change during runtime. In this case I track the change and update graphics inside updateDisplayList() method. I removeChild() my decoration, reinstantiate it, and addChild() again. So eventualy new decoration is upon children. This is bad. I was inventing sevaral "smart" methods of overcoming this, but I'd like to know what techniques you guys use in this case. Any discussion would be appriciated
__________________
fly high
rawmantick is offline   Reply With Quote
Old 11-15-2008, 01:47 AM   #2
pj-co
Site Contributor
 
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
Default

can you post some example code? I'd be curious to know what you worked out with this as well.
pj-co is offline   Reply With Quote
Old 11-15-2008, 09:10 AM   #3
rawmantick
Pipty rupees only!
 
rawmantick's Avatar
 
Join Date: Jul 2007
Location: Novosibirsk, Russia
Posts: 1,713
Default

I don't actually have the code near myself at the time. But I can try to describe my last technique I'v noticed for myself to use.

Let's say I have a component, that would have additional decorations. All of them should be upon usual children of my component.

1. inside overriden createChildren() method I add a sort of layer, which is kind of container for decorations
ActionScript Code:
override protected function createChildren():void {     super.createChildren();     if( _decorationLayer == null )     {         _decorationLayer = new UIComponent(); //well maybe Canvas ?         addChild(_decorationLayer);         _decorationDepth = getChildIndex(_decorationLayer);     } } private var _decorationLayer:UIComponent = null; private var _decorationDepth:Number;

2. To knwo exactly, that no child will bubble up and become upon our decorations,lets make some sorta trick
ActionScript Code:
override public addChild(arg:DisplayObject) {     super.addChild(_decorationDepth+1); }
This will add a child under decorations. Ofcourse you should override all relative methods.

3. And finaly inside updateDisplayList() method if some skins updated - i simply reattach them to my decoration style in a desired order. The whole decoration will remain upon children.

This code is just a main idea and has much bugs for sure. Since it came from my head right now. But when implementing some exact component - the code will be built according to idea but more accurately.

Hope I'm understandable.
__________________
fly high
rawmantick is offline   Reply With Quote
Old 11-15-2008, 04:15 PM   #4
pj-co
Site Contributor
 
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
Default

I sort of understand I think. You have a DisplayObject that contains style information you want to apply to all children of your component. You keep it at a specific depth so you can access it later and reapply it to the children if the style changes. Does that sound about right? (Sorry for all the questions. My knowledge of flex is still somewhat limited). If I understand this, why is that you need to have the decorations object at a specific depth? Is that how it bubbles up and sets the styles of other objects automatically? Couldn't you just call setStyle() on them?
pj-co is offline   Reply With Quote
Old 11-16-2008, 04:45 PM   #5
rawmantick
Pipty rupees only!
 
rawmantick's Avatar
 
Join Date: Jul 2007
Location: Novosibirsk, Russia
Posts: 1,713
Default

You understand me right generaly.

Quote:
Couldn't you just call setStyle() on them?
Well, you can set style on component that does support styles. But sometimes I realy need such a specific style support, so only recreating a decoration is the only way. Imagine you have a panel-extending component, which has for example several DisplayObject (flash level, not Flex) decorations. For one of them you define a class (say skin, symbol from flash IDE lybrary) and padding from left and top borders of the component. For another you define several classes (IDE symbols) that somehow change on different events (say it's a behavior of this decoration). Yes, you can create a separate component for each of the decoration and simple re-style them from the main container component. But the specifics of those would be so strog, so there is no reason to make them separate. So you have to to make all those weird skin manipulations right inside you panel-extending component, constantly keeping in mind their order and correspondance to current style properties.

Also, as for just setting style, you cannot always set a style just because it's possible they don't exist at all. That's what all these things about - to support custom and sofisticated skins styles you have to make some sort of tricks to kepp decorations order correct for you...

Wooff... I hope I'm undesrstandable. Sory for my english, it's not my native
__________________
fly high
rawmantick is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flex/ ActionScript Tile Component j4kes Flex 2 & 3 6 08-26-2008 11:01 AM
Access Flex Objects from Flash created component Selecters75 Flex 2 & 3 1 04-28-2008 09:13 AM
Passing parameters on initialization of custom flex component? Daedalus Flex 2 & 3 4 02-19-2008 11:01 PM
removeMovieClip does not work when a child component is present Amn Components 2 08-15-2005 04:18 PM
Control child movie from parent movie? TheJazzMan ActionScript 2.0 6 04-29-2005 05:44 PM


All times are GMT. The time now is 10:35 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.