Flex CursorManager vs jloa



No Comments

Share




So there i was, trying to build my latest application which involved run-time cursor loading/usage.
I knew that the flex sdk had that static CursorManager class (i.e. mx.core.CursorManager), but as i looked up the manual – there’s no loadIcon() method, only setters that require class references which is sooooo unhandy if u deal with run-time loading assets (like i do).
So, i got myself some coffee, opened the eclipse and after some time spend – eureka!
I came to this slight solution which besides is elementary. :)


Ok, less words – more action.
Here’s the class and the usage below:


////////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2009 Julius Loa | jloa@chargedweb.com
//  All Rights Reserved.
//  license: GNU {http://www.opensource.org/licenses/gpl-2.0.php}
//  notice: just keep the header plz
//
////////////////////////////////////////////////////////////////////////////////

package com.chargedweb.utils
{
import flash.net.URLRequest;
import flash.display.Loader;

/**
 * CursorFactory class for usage with @see mx.core.CursorManager
 *
 * @example
 * <pre>
 * import com.chargedweb.utils.CursorFactory;
 * import mx.core.CursorManager;
 *
 * CursorFactory.URL = "../assets/skins/icons/my_cursor.png";
 * CursorManager.setCursor(CursorFactory);
 * </pre>
 */

public class CursorFactory extends Loader
 {
   /**
    * Custom cursor url value
    */
   public static var URL:String;

   /**
    * Constructor
    */
   public function CursorFactory()
   {
      super();
      if(URL) load(new URLRequest(URL));
   }
 }
}

And the sample usage code (in case u didn’t notice it in the class comments):


import com.chargedweb.utils.CursorFactory;
import mx.core.CursorManager;

CursorFactory.URL = "../assets/skins/icons/my_cursor.png";
CursorManager.setCursor(CursorFactory);

Leave a Reply

Spam protection by WP Captcha-Free