MXML Components

View: New views
2 Messages — Rating Filter:   Alert me  

MXML Components

by Graham Pearson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 
Hi All:

I am trying to grasp my head around creating MXML Components while
utilizing Flash Remoting for one of my applications. What I am trying to
do is break up my application from one single mxml file with viewstacks
to a smaller file with mini components. Most of my Actionscript is in an
external file which is included in the main mxml file.

My first task is to get the Login Page into its own MXML Component and
have it work. Right now I have the Panel with all of the components in
the file and on my main mxml file I reference it like <Custom:LoginPanel
/>. This component has 2 buttons and 2 textinput areas. The textinput
areas are named Username and Password. One of the buttons has an
click="AccountLogin();" which is defined in the Main mxml application
like so:

private function AccountLogin():void {
~    FlexNIESCHelpDeskWS.CheckAccount(Username.text, Password.text);
}

Having this function in the main mxml file I am getting an Error in FB3
which says Access to undefined property Password and Access to undefined
property Username. Now if I move this function into my LoginPanel.mxml
file I am getting an Access to undefined property FlexNIESCHelpDeskWS
which this is defined in my main mxml file.

I am wanting to break up this one file into many smaller files as trying
to debug one large file is becoming a pain in the rear. I am also trying
to google for an example of what I am trying to do but my search
technique on this is not producing good results. Can anyone give advice
as to where I can look to grasp this concept.




-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: GnuPT 2.6.2.1 by EQUIPMENTE.DE
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iD8DBQFIZnAx3GqPAgBSy90RAn2oAJ9S2XXvhWCgI0wiNPF2gwtF1HAY2wCdFvFs
5IDiY4CPAenKgDEsr6P9Btk=
=3c/3
-----END PGP SIGNATURE-----


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j

Archive: http://www.houseoffusion.com/groups/Flex/message.cfm/messageid:5365
Subscription: http://www.houseoffusion.com/groups/Flex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.37

Parent Message unknown RE: MXML Components

by Dave Watts :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I am trying to grasp my head around creating MXML Components
> while utilizing Flash Remoting for one of my applications.
> What I am trying to do is break up my application from one
> single mxml file with viewstacks to a smaller file with mini
> components. Most of my Actionscript is in an external file
> which is included in the main mxml file.
>
> My first task is to get the Login Page into its own MXML
> Component and have it work. Right now I have the Panel with
> all of the components in the file and on my main mxml file I
> reference it like <Custom:LoginPanel />. This component has 2
> buttons and 2 textinput areas. The textinput areas are named
> Username and Password. One of the buttons has an
> click="AccountLogin();" which is defined in the Main mxml
> application like so:
>
> private function AccountLogin():void {
> ~    FlexNIESCHelpDeskWS.CheckAccount(Username.text, Password.text);
> }
>
> Having this function in the main mxml file I am getting an
> Error in FB3 which says Access to undefined property Password
> and Access to undefined property Username. Now if I move this
> function into my LoginPanel.mxml file I am getting an Access
> to undefined property FlexNIESCHelpDeskWS which this is
> defined in my main mxml file.

Well, the main application file can't refer to things in your component
unless you expose them as properties, and your component doesn't know
anything about what's in the main application file either.

> I am wanting to break up this one file into many smaller
> files as trying to debug one large file is becoming a pain in
> the rear. I am also trying to google for an example of what I
> am trying to do but my search technique on this is not
> producing good results. Can anyone give advice as to where I
> can look to grasp this concept.

The easiest way would be to create bindable variables in your component, and
reference them from your application. That would involve something like
this:

<!-- in your component -->
<mx:Script>
<![CDATA[
[Bindable]
public var username:String;
[Bindable]
public var password:String;
private function submitHandler():void
{
        username = Username.text;
        password = Password.text;
}
]]>
</mx:Script>
<mx:TextInput id="Username"/>
<mx:TextInput id="Password"/>

<!-- in your application -->
<mx:Script>
<![CDATA[
private function AccountLogin():void
{
    FlexNIESCHelpDeskWS.CheckAccount(loginPanel.username,
loginPanel.password);
}
]]>
</mx:Script>
<Custom:LoginPanel id="loginPanel"/>

A better solution, though, would be to define custom events in your
component, and assign event handlers to the component instance in your
application file. This is fairly complicated (the first time you do it, at
least) but lets you provide a loose coupling between your components and the
application. I don't have time to write a code sample here right now, but
you can probably find examples on the web.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/

Fig Leaf Software provides the highest caliber vendor-authorized
instruction at our training centers in Washington DC, Atlanta,
Chicago, Baltimore, Northern Virginia, or on-site at your location.
Visit http://training.figleaf.com/ for more information!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date
Get the Free Trial
http://ad.doubleclick.net/clk;203748912;27390454;j

Archive: http://www.houseoffusion.com/groups/Flex/message.cfm/messageid:5366
Subscription: http://www.houseoffusion.com/groups/Flex/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=17837.14401.37
LightInTheBox - Buy quality products at wholesale price!