[flex_india:30170] MvieClip or Sprite to ByteArray

248 views
Skip to first unread message

Arindam Mojumder

unread,
May 25, 2010, 3:39:26 AM5/25/10
to FLEX INDIA
Hello friends,

Is it possible to convert MvieClip or Sprite to ByteArray, so I can load swf fine once and clone it in an application, like I do with BitmapData?

--
-----------------------------------------------------------------------
With best regards
Arindam Mojumder
-----------------------------------------------------------------------
Flickr:- http://www.flickr.com/photos/arindam-mojumder/sets/
Facebook:- http://www.facebook.com/Arinda.Mojumder
Twitter:- http://twitter.com/arindam_arindam
Google Blog:- http://scripto-mania.blogspot.com/
Wordpress-blog:- http://nilbristi.wordpress.com/
-----------------------------------------------------------------------

--
You received this message because you are subscribed to the Google Groups "Flex India Community" group.
To post to this group, send email to flex_...@googlegroups.com.
To unsubscribe from this group, send email to flex_india+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/flex_india?hl=en.

rishi narang

unread,
May 25, 2010, 4:36:02 AM5/25/10
to flex_...@googlegroups.com
if using flex4 use fx:library tag to load the swf, reuse that swf from the library

Arindam Mojumder

unread,
May 25, 2010, 5:39:50 AM5/25/10
to flex_...@googlegroups.com
Actually I am working on a online drawing/post card design application in Actionscript 3.0.
There has an option to save data. Next time when user will login then he can reedit the drawing again.
So I was thinking to convert the drawing palette as  a bytesArray and save it as a .txt file. So that In future I can reload the .txt file
and convert it to original movieClip/Sprite. I just don't want to go through xml structure, bcoz it will make the application very complecated.

Is it possible to convert MvieClip or Sprite to ByteArray???

I have a code to convert any swf file to bytesArray. and save it as a .txt file and again load this .txt file with all the properties.
 Below is my code, just copy paste it on the first frame.


loadSwf();//---------- loading external swf file and convert it to bytesArray and save it as a .txt file
//loadTxt();//---------loading the .txt file and display it on the stage with the original property.

function loadSwf():void {
var bytes:ByteArray = new ByteArray ();
var ldr:URLLoader = new URLLoader();
ldr.dataFormat = URLLoaderDataFormat.BINARY;

var req:URLRequest = new URLRequest("sample.swf");
ldr.addEventListener(Event.COMPLETE, completeHandler);
ldr.load(req);


function completeHandler(e:Event):void {
bytes=ldr.data;
var s:String="";
for (var j : int = 0; j < bytes.length; j++) {
var n:String=bytes.readUnsignedByte().toString(16);
if (n.length<2) {
n="0"+n;
}
s+=n;
}
trace(s);
}
}
function loadTxt():void {
var ldr1:URLLoader = new URLLoader();
var ldr:Loader=new Loader();
var req:URLRequest = new URLRequest("swfBytes.txt");
ldr1.addEventListener(Event.COMPLETE, completeHandler1);
ldr1.load(req);
function completeHandler1(e:Event):void {
var bA =new ByteArray ();
var data1:Array=ldr1.data.split("");
var data2:Array=[];
for (var i : int = 0; i < data1.length; i +=2) {
data2.push("0x"+data1 [i]+data1[i+1]);
}
for (var j : int = 0; j < data2.length; j ++) {
bA[j] = data2[j];
}
ldr = new Loader ();
//ldr.contentLoaderInfo.addEventListener (Event.COMPLETE, completeHandler);
ldr.loadBytes(bA);
addChild(ldr);
}
}

rishi narang

unread,
May 25, 2010, 6:09:05 AM5/25/10
to flex_...@googlegroups.com
if you just want to convert movieclip or sprite to bytearray.....then
take the bitmap snapshot of movieclip ....convert to bytearray


LOOK HERE: http://www.adobe.com/devnet/flash/quickstart/filereference_class_as3/


this uses ByteArray with JPGEncoder class

Arindam Mojumder

unread,
May 25, 2010, 6:22:08 AM5/25/10
to flex_...@googlegroups.com
no man I do't want the file as an image. Check my added code. then only you can understand it. I want to load the movieClip with all its property. so that I can re-edit the MovieCLip.
--

rishi narang

unread,
May 26, 2010, 1:33:37 AM5/26/10
to flex_...@googlegroups.com
if you want editable movieclip data to be stored externally then FXG
format can help u, u can load FXG as AS3 component modify it and save
back

On Tue, May 25, 2010 at 3:52 PM, Arindam Mojumder

arindam

unread,
Nov 15, 2012, 11:32:49 PM11/15/12
to flex_...@googlegroups.com
Hello Hubert 

No I didn't get any solution still now. :(

On Tuesday, May 25, 2010 1:09:26 PM UTC+5:30, arindam wrote:
Hello friends,

Is it possible to convert MvieClip or Sprite to ByteArray, so I can load swf fine once and clone it in an application, like I do with BitmapData?

--
-----------------------------------------------------------------------
With best regards
Arindam Mojumder
-----------------------------------------------------------------------
Flickr:- http://www.flickr.com/photos/arindam-mojumder/sets/
Facebook:- http://www.facebook.com/Arinda.Mojumder
Twitter:- http://twitter.com/arindam_arindam
Google Blog:- http://scripto-mania.blogspot.com/
Wordpress-blog:- http://nilbristi.wordpress.com/
-----------------------------------------------------------------------

--
You received this message because you are subscribed to the Google Groups "Flex India Community" group.
To post to this group, send email to flex_...@googlegroups.com.
To unsubscribe from this group, send email to flex_india+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages