ActionScript 3.0, Adobe Flex

MATE CacheSetter.. a quick and dirty introduction

One of the newer classes in the MATE Flex Framework yet to be documented is the CacheSetter.
It’s nothing overly fancy, but it does exactly what it promises… it allows you to set the Cache from an ActionTag.

Let’s examine the code below… it’s a standard MATE EventMap with a couple of eventhandlers which offers to exit an AIR application when the User clicks anywhere on it… the applications for such a feature might be quite limited, but that’s what I could think of at 4:40 AM in Bangkok after almost 2 hours of being teleconferencing with the Flex Team sitting in California and it proves the point with the CacheSetter close to a minimal implementation.

NativeSystemEventMap.mxml




	
		
	

	

		
			
		

		
			
		

	


For the sake of completion, I will also bring the code to the AIR application itself…


<s>

	
		
	

</s>

One of the more interesting and intricate details (and eventually why this exercise is interesting), is to see that it uses the Class reference as the cacheKey and that you eventually would be able to use any class or hashable object and chain as the cacheKey. If the cacheKey is NOT set explicitly it will default to use the class type of the Generator attribute, but if you are working with MATE the Cache class is one of the classes it makes the most sense to take an extra look at…

CacheSetter (Source)
http://code.google.com/p/mate-framework/source/browse/trunk/src/com/asfusion/mate/actions/CacheSetter.as

Cache (Source)
http://code.google.com/p/mate-framework/source/browse/trunk/src/com/asfusion/mate/core/Cache.as

Cache (Documentation
http://mate.asfusion.com/api_docs/com/asfusion/mate/core/Cache.html

Advertisements

13 thoughts on “MATE CacheSetter.. a quick and dirty introduction

  1. Hey Peter! I’ve been trying to do something similar myself. I’m having problems however setting the alwaysInFront property on my applications WindowedApplication. I can call a method on it, but I can’t seem to set a property. I’ve tried using PropertySetter but it doesn’t seem to work.

    Have you any ideas how you might achieve this?

    1. Hi Scott,

      I would imagine that a PropertyInjector should be able to do the trick.
      Have you tried adding something along the lines of the following to your EventMap ?

      <mate:EventHandlers type="{ FlexEvent.APPLICATION_COMPLETE }">
      	<mate:MethodInvoker generator="{ Window }" method="open" />
      </mate:EventHandlers>
      
      <mate:Injectors target="{ Window }">
      	<mate:PropertyInjector source="{ true }" targetKey="alwaysInFront" />
      </mate:Injectors>
      
  2. Hey Peter,

    Thanks for the answer. Yeah, I actually tried PropertyInjector, but that didn’t work either. Let me expand on the situation a little. Users click a button, a new native window opens, from that window I fire an event which updates my Manager inside EventHandlers. I know this backwards communication works because I use the EventDispatcher tag to dispatch the events in the popped native window (I’ve read all about events and the AIR display list between native windows).

    Any other ideas?

  3. Hi Scott,

    Hmmmm…. I actually ran the code above prior to posting the comment and it works for me… but it might just be the simplified case here that works and perhaps me not completely understanding your issue at hand.
    However, as an alternative… have you tried using the DataCopier ? Sometimes it can come in handy when I need to do a low level copy of data.

    // Peter

  4. I think my main problem is I’m unsure how to target the main WindowedApplication. I’ve tried Window, WindowedApplication, NativeApplication and main (the name of the main .mxml file).

    In fact, I’ve done a few traces on ‘this’. One from the the creationComplete on the actual WindowedApplication mxml which returned ‘main0’. Then I used MethodInvoker to target generator ‘{main}’ and that traced back ‘main72’.

    So I assume MATE is generating another Class instance…?

  5. Quickly remembering the topic of the initial post… have you by any chance tried something similar to this ?

    <mate:EventHandlers type="{ FlexEvent.CREATION_COMPLETE }">
    	<mate:CacheSetter instance="{ FlexGlobals.topLevelApplication }" cacheKey="{ main }" />
    	<mate:PropertySetter source="{ true }" targetKey="alwaysInFront" generator="{ main }" />
    </mate:EventHandlers>
    
  6. Woops, sorry… I’m so used now to working in Flex4 that I forget about it… 🙂
    I suppose the above statement would something like this…

    <mate:EventHandlers type="{ FlexEvent.CREATION_COMPLETE }">
    	<mate:CacheSetter instance="{ Application.application }" cacheKey="{ main }" />
    	<mate:PropertySetter source="{ true }" targetKey="alwaysInFront" generator="{ main }" />
    </mate:EventHandlers>
    
  7. This is great !! Just what I needed to get my multiwindowed AIR app working. This CacheSetter tag could make my MATE life much easier. Thanks Peter!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s