Hi Jules,
Object Oriented programming in my mind is about making use of references
to objects. With this in mind, here is a way I use to centralise common
functionality (functions) that I can access throughout my application:
1. Create an object in the Application mxml file - this will be
referenced throughout your application components
eg: objApp:Object = new Object();
2. Create functions inside a script block in the Application mxml file
eg:
public function myUsefulFunction(): void {
...
}
3. Add references to my functions to objApp object - no () after the
function name as it is a reference to it, not a call to it
eg: objApp.myUsefulFunction = myUsefulFunction;
I can also include function classes here and make reference to their
functions
4. Pass objApp as a reference to each component - I must be sure that
the deepest component is chained back to the Application mxml by passing
this reference through all its parents
eg: <comp:mypanel id="" objApp="{objApp}" .... />
5. Inside each component, bind objApp
eg:
[Bindable]
public var objApp:Object;
6. Call my functions from whereever I want to, from any component that
has a reference to objApp
eg: objApp.myUsefulFunction();
7. I am not just limited to passing references to functions this way
either. I can pass references to child objects and even move them
around the stage, etc. also
eg: objApp.myPanel.x = objApp.myOtherPanel.x + objApp.myOtherPanel.width
+ 10;
Hope this helps you. Works really well for me. It seems a very easy
way to use the power of object oriented referencing to talk to anything,
anywhere in an application. And if I ever want to know anything about
any object, I can usually query it via reference to objApp.
Could call it the objApp framework if it hasn't already got a name :o)
Cheers,
Martyn
Jules Suggate wrote:
>
> Is it possible for an MXML file to implement an interface? Sounds
> intriguing ... but won't resolve my issue unfortunately. It's the
> implementation code that I want them to share.
>
> I have developers on my team who are less than keen on having to
> duplicate repetitive code around the place -- they want to focus on
> cool effects, state transitions and backend integration :-)
>
> And I don't want repeated code everywhere in the app since if we want
> to change something, there'll eventullay be hundreds of places where
> we have to do so if the code is copy+pasted around the place...
>
> On Fri, Jan 30, 2009 at 05:25, Fotis Chatzinikos
> <[email protected] <mailto:[email protected]>> wrote:
>
> why do not you make your components implement an interface with
> these methods you describe?
>
>
> On Thu, Jan 29, 2009 at 10:54 AM, Jules Suggate
> <[email protected] <mailto:[email protected]>> wrote:
>
> Just to resume this thread, what I meant was to still use MXML
> and all the Flex components, but to introduce common
> functionality to all our Views (mxml files). Perhaps it's
> better to think of weaving this in than using inheritance,
> since that would require multiple inheritance AFAICT.
>
> I don't want anything fancy -- just a getter/setter pair:
>
> public function get model():IViewModel
> {
> // some common code
> }
> private var _model:IViewModel;
> public function set model(value:IViewModel):void
> {
> // more common code
> }
>
> To save writing out this code again and again, would I have to
> put this code in an include file, and include from each View?
>
>
>
> On Thu, Dec 18, 2008 at 06:41, Alex Harui <[email protected]
> <mailto:[email protected]>> wrote:
>
> In theory, if your base class implements IUIComponent,
> then your visual components will work in Flex
>
>
>
> *From:* [email protected]
> <mailto:[email protected]>
> [mailto:[email protected]
> <mailto:[email protected]>] *On Behalf Of *Jules
> Suggate
> *Sent:* Wednesday, December 17, 2008 8:56 AM
> *To:* [email protected]
> <mailto:[email protected]>
> *Subject:* [flexcoders] Common base class for components
>
>
>
> Hi list, anyone know if it's possible to have all our
> components inherit from a common base component of our own
> making?
>
> There are some things in our app that every View component
> will have to do at loadtime, and it'd be nice to just
> write that code once and have all the other components
> inherit it...
>
> Last time I checked in Flex 3 Beta 2 there was some vague
> suggestion of using "Template Components", but that seemed
> like an afterthought in the SDK at the time. Just thought
> I'd check to see if you knew of any tricks for doing it :)
>
> Perhaps even an include file would be the way to go...
--
============================
Dr Martyn Bowis (PhD Engineering)
Director Net Design Ltd
New Zealand
www.netdesign.co.nz <http://www.netdesign.co.nz>
Mob: +64 21 932626
Skype: mbowis
MSN: mbowis @ msn.com
<http://www.netdesign.co.nz>
Truth brings Freedom
============================
The content of this email is confidential.
If you are not the intended recipient,
you must not use or distribute this
information in any way, shape or form.
Please notify the send of this error.
Thank you.