开发者

Drying out/refactoring flex/actionscript code

开发者 https://www.devze.com 2023-01-03 21:20 出处:网络
I have something like 10 components that have code that\'s very similar, except for the target that it\'s applied to and some other minor differences.

I have something like 10 components that have code that's very similar, except for the target that it's applied to and some other minor differences.

For example, I return xml to component1 and component2 that differs in this way:

component 1: event.result.names.name
component 2: event.result.pho开发者_运维知识库nes.phone

I then bind these to a List, and the name of that list differs by component.

component 1: nameslist.dataProvider = 
component 2: phoneslist.dataProvider = 

How do I create a single method that would accept as parameters just the names/pointers/references to the objects I need worked on. For examples nameslist or phoneslist as List or .phones.phone vs. .names.name for the structure of the xml returned?


It sounds to me like you can use a function as parameters to your component.

So, you'll have a property like this:

public var dataProviderFunction : Function;

and the value you'd give it might be something like this:

public function getNamesDataProvider(object:XML):xml{ return xml.namesList.dataProvider }

Or like this:

public function getNamesDataProvider(object:XML):xml{ return xml.phonesList.dataProvider }

Take a look at how the List class source code and see how the labelFunction and itemToLabel are implemented.

0

精彩评论

暂无评论...
验证码 换一张
取 消