Well, only problem with Composition is it's now a black box; that can be
good or bad. For example, if your class is the only one ever operating on
the custom Repeater, then sure, that's fine. However, if you ever want to
expose those methods, you have to write proxy methods for them all
including re-doing all the getters and setters.
So, using a List in a form via composition is fine; you have buttons in
that form that add/delete items from the list. From that point on,
however, no one else can ever interact with that lists data.
...unless you expose the dataProvider, or the dataProvider is public. If
it is, you can only operate on that dataProvider via the dataProvider API.
If that's ok with you, that's ok with me. IF, however, you are building
a re-usable View, then that isn't very eloquent. Just depends on how your
going to use it. List for example can be extended if you want. Most
people, however, use it via composition.
> Thanks. That make it a lot clearer.
>
> Although, am not sure I understand why you would use the mixin
> approach here compared to using Composition.
> Are there any benefits of doing it this way as opposed to say:
>
> Embed a dataProvider inside "Comp.mxml" and have the comp listen for and
> handle the modelChanged event of the DP ?
>
> TIA
>
> - superabe
>
>
>
>
>
> On 1/7/06, JesterXL <[EMAIL PROTECTED]> wrote:
>>
>> *** resending, other one got lost in the ether I spose: 2:48pm
>> 1.7.2006***
>>
>> In a nutshell, DataSelector is a mixin. A mixin adds methods and
>> properties to a class at runtime. Since you cannot do multiple
>> inheritance
>> in ActionScript, using a mixin is a way around that. DataSelector adds
>> dataProvider powers to a class:
>>
>> DataSelector.initialize(YourClass);
>>
>> Any class that utilizes DataSelector gets a length property.
>> DataSelector
>> gives a class pretty much all the DataProvider methods (which are really
>> proxies to the dataProvider it contains a reference to), length being
>> one of
>> them. So:
>>
>> yourComponent.length
>>
>> is the same as:
>>
>> yourComponent.dataProvider.length
>>
>>
>> Yes, modelChanged fires everytime you use a DataProvider method on a
>> dataProvider or dataProvider component.
>>
>> a = ["one", "two", "three"];
>> yourComponent.dataProvider = a;
>>
>> a.addItem("cow"); // fires modelChanged
>> a.push("cheese"); // does not fire modelChanged
>> yourComponent.addItem("moo"); // fires modelChanged
>>
>> ModelChanged actually has an object that is passed to it, the event
>> object, that has information about what changed. You can use a switch
>> statement to know what changed, and how, and more intelligently draw
>> your
>> component. A note; this is a fuoi$%(*)$% load of work. If you don't
>> believe me, go look in DataGrid.as.
>>
>> So, to be lazy, I just ignore it and redraw everytime. Keep in mind,
>> even
>> if you use the code above, it'll only redraw once:
>> - modelChanged fired for setting the dataProvider
>> - modelChanged fired for adding "cow" to it
>> - modelChagned fired for adding"moo" to it
>>
>> Since I use a doLater, and only 1, it'll only redraw once per frame.
>> ----- Original Message ----- *From:* superabe
>> superabe<[EMAIL PROTECTED]>
>> *To:* [email protected]
>> *Sent:* Saturday, January 07, 2006 11:38 AM
>> *Subject:* Re: [flexcoders] Alternative to Repeater
>>
>>
>> Thanks for the help.
>> Couple of question
>>
>> 1 .What do you mean by - utilize Data Selector on that class ?
>>
>> 2. In the redrawForm method what does the value "length" represent.
>> If it is the length of the dataProvider, am not clear how that was
>> established
>>
>> 3. Does "modelChanged" fire every time the dataProvider changes?
>> If so seems like it would redraw the entire form even if only one item
>> in
>> the array changed (say using addItem).
>>
>> Thanks,
>>
>> - superabe
>>
>> On 1/7/06, JesterXL <[EMAIL PROTECTED]> wrote:
>> >
>> > You basically do:
>> > - create a new abstract base class for your component as ActionScript
>> > - utilize DataSelector on that class
>> > - extend that class in a new file
>> > - have the new file do something like this
>> >
>> > function modelChanged()
>> > {
>> > cancelAllDoLaters();
>> > doLater(this, "redrawForm");
>> > }
>> >
>> > function redrawForm()
>> > {
>> > canvas_mc.destroyAllChildren();
>> > var i:Number = length;
>> > while(i--)
>> > {
>> > var item:Object = getItemAt(i);
>> > canvas_mc.createChild(SomeComponent);
>> > }
>> > }
>> >
>> >
>> > What is happening here is whenever the dataProvider changes, the form
>> is
>> > redrawn. It's only redrawn once per frame in case dataProvider has 50
>> > billion changes.
>> >
>> > If you see the createChild call for the canvas, basically you could
>> put
>> > in logic, say, to create images, and then call load on them based on
>> the url
>> > for the current item.
>> >
>> > Then, you can finally use that AS component as MXML elsewhere. Make
>> > sense?
>> >
>> >
>> > ----- Original Message ----- *From:* superabe
>> superabe<[EMAIL PROTECTED]>
>> > *To:* [email protected]
>> > *Sent:* Saturday, January 07, 2006 11:09 AM
>> > *Subject:* [flexcoders] Alternative to Repeater
>> >
>> >
>> > Is there an alternative to using a Repeater , that I could make use of
>> > in my component (AS based).
>> > For e.g.
>> >
>> > Say I have a component called "Comp"
>> >
>> > Comp.mxml (Pseudo-code)
>> > ==========> > <mx:VBox>
>> > <mx:Script>
>> >
>> > public var dp:Array;
>> > </mx:Script>
>> >
>> > <mx:Repeater dataProvider="{dp}">
>> > <mx:Image source="{currentItem.url}"/>
>> > </mx:Repeater>
>> >
>> > </mx:VBox>
>> >
>> > Comp is used in Main.mxml and the dataprovider for Comp is set in
>> > Main.mxml.
>> > Main also may add and remove items from the the dataprovider for Comp
>> on
>> > subsequent events.
>> >
>> > I would like to write Comp as an Actionscript class and avoid a
>> Repeater
>> > all together.
>> > I may be missing something really obvious, but how would I do that ?
>> >
>> > TIA,
>> >
>> > - superabe
>> >
>> >
>> >
>> >
>> >
>> >
>> > --
>> > Flexcoders Mailing List
>> > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
>> > Search Archives:
>> > http://www.mail-archive.com/flexcoders%40yahoogroups.com
>> >
>> >
>> > ------------------------------
>> > YAHOO! GROUPS LINKS
>> >
>> >
>> > - Visit your group
>> "flexcoders<http://groups.yahoo.com/group/flexcoders>"
>> > on the web.
>> >
>> > - To unsubscribe from this group, send an email to:
>> > [EMAIL PROTECTED]<[EMAIL PROTECTED]>
>> >
>> > - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>> > Service <http://docs.yahoo.com/info/terms/>.
>> >
>> >
>> > ------------------------------
>> >
>>
>>
>>
>> --
>> Flexcoders Mailing List
>> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
>> Search Archives:
>> http://www.mail-archive.com/flexcoders%40yahoogroups.com
>>
>>
>> ------------------------------
>> YAHOO! GROUPS LINKS
>>
>>
>> - Visit your group
>> "flexcoders<http://groups.yahoo.com/group/flexcoders>"
>> on the web.
>>
>> - To unsubscribe from this group, send an email to:
>> [EMAIL PROTECTED]<[EMAIL PROTECTED]>
>>
>> - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>> Service <http://docs.yahoo.com/info/terms/>.
>>
>>
>> ------------------------------
>>
>
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/