History | Log In     View a printable version of the current page.  
Issue Details (XML)

Key: SDK-16181
Type: Feature Request Feature Request
Status: Closed Closed
Resolution: Duplicate
Priority: None None
Assignee: Matt Chotin
Reporter: Nate Beck
Votes: 3
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Flex SDK

Flex should support accessors on a component level.

Created: 07/23/08 10:51 AM   Updated: 07/24/08 05:04 PM
Component/s: MXML Components
Security Level: Public (All JIRA Users )

Issue Links:
Duplicate
This issue duplicates:
SDK-678 ECR: Specify Accessor in MXML C Closed
SDK-219 Access-controlled MXML Properties C Deferred
 


 Description  « Hide
[ResourcesTree.mxml]
<mx:Canvas xmlns:mx="..." width="400" height="300">
<mx:Script>
...
</mx:Script>
<mx:WebService details.... />
<mx:Tree id="_tree" change="{dispatchEvent(event)}"/>
</mx:Canvas>

Outside of my Resources tree, I don't want anyone to be able to access my tree component. However it's automatically compiled as public.

Say I want to add an event listener to the tree change event, I want to force people using my component to listen to the ResourcesTree, not the sub-component.

For example:
var myResources:ResourcesTree = new ResourcesTree();
myResources.addEventListener(Event.CHANGE, onResourceChange); // GOOD
myResources._tree.addEventListener(Event.CHANGE, onResourceChange); // BAD!

private function onResourceChange(event:Event):void
{
  trace("yay captured");
}

This is important for following standard OOP practices. I can't encapsulate my custom MXML components and protect their inner workings. It would be nice for components to allow public, private, protected and etc.

 All   Comments      Sort Order:
Tink - [07/23/08 11:06 AM ]
An accessor tag would be a great addition to MXML. Please gives us the ability to use the accessors provided to us in AS 3.0.

Josh Tynjala - [07/23/08 02:16 PM ]
Encapsulation is fun! :)

Sid Maskit - [07/23/08 05:56 PM ]
I have not tried it out, but this blog post seems to provide a solution by using a metadata tag: http://blog.ashier.com/2008/03/25/hiding-properties-in-flex-components/. Perhaps all that is needed is better documentation.

Nate Beck - [07/23/08 06:10 PM ]
I checked out that article with high hopes that it would work... it doesn't. Unless I'm doing something wrong:

[ExcludeTesting.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute" xmlns:local="*" creationComplete="init();">
   <mx:Script>
      <![CDATA[
         import mx.controls.Button;
         
         private function init():void
         {
            var mybtn:Button = myComp.btn;
            mybtn.label = "Wootage";
         }
      ]]>
   </mx:Script>
   <local:MyComponent id="myComp" />
</mx:Application>

[MyComponent.mxml]
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"; width="400" height="300">
   <mx:Metadata>
      [Exclude(name="btn", kind="property")]
   </mx:Metadata>
   <mx:Button x="167.5" y="146" label="Click Me" id="btn" />
</mx:Canvas>

It still allows me to access the sub-component, change properties on the sub-component etc. So unfortunately this doesn't solve the issue.

Sid Maskit - [07/24/08 12:27 AM ]
I'm in the same boat. I read the blog post, thought it sounded great, and posted about it here. Then I tested it (which I guess the original author didn't do), found it didn't work, and came back to post a correction. Sorry about the misinformation. BTW I've also commented at the site I quoted so hopefully others won't repeat my mistake.