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

sunithasAsked:
Who is Participating?
 
Gary BenadeConnect With a Mentor Commented:
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:
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:
please close this question if you don't need any more help, or let me know if you need anything else
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.