[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2194
  • Last Modified:

Flex create Class object dynamically

Hi,

     I need to create a custom cursor(image) in my flex application. The image is created dynamically.


If the image is static I can do the below and it works fine.

[Embed(source="assets/cursor1.png")]
            [Bindable]
                  public var Cursor1:Class;  

CursorManger.setCursor(Cursor1);


If the image is dynamically created as in my case, I am not sure how to create Class object.


please advice

thanks in advance


[Embed(source="assets/cursor1.png")]
            [Bindable]
			public var Cursor1:Class;  
 
CursorManger.setCursor(Cursor1);

Open in new window

0
sunithas
Asked:
sunithas
  • 3
1 Solution
 
Gary BenadeCommented:
tutorial to give you a red dot cursor
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
	<mx:Script>
		<![CDATA[
			import mx.managers.CursorManager;
			
			private function init():void
			{
				CursorManager.setCursor( MyCustomCursor);
			}
		]]>
	</mx:Script>	
</mx:Application>
 
 
// save this file as MyCustomCursor.as in the same dir as the file above
 
package
{
	import flash.display.Sprite;
 
	public class MyCustomCursor extends Sprite
	{
		public function MyCustomCursor()
		{
			super();
 
			this.graphics.beginFill( 0xFF0000);
			this.graphics.drawCircle(10,10,10);			
		}
		
	}
}

Open in new window

0
 
sunithasAuthor Commented:
That would be a shape like circle how about an Image. I create image on the fly and have the image in an bytearray. How can I show it ?
0
 
Gary BenadeCommented:
not an easy thing to do, but there is a way. go check this out:
http://stackoverflow.com/questions/428559/flex-converting-a-jpg-to-a-class-at-runtime

What he is doing is quite clever, referencing the applications bitmapdata inside the cursor class constructor.
Load your bytearray into the Applications bitmapaData using writeBytes, the rest should work as is
0
 
Gary BenadeCommented:
please close this question if you don't need any more help, or let me know if you need anything else
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now