Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Filereference.save from multiple loaders?

Community Beginner ,
Jan 06, 2013 Jan 06, 2013

Hey folks,

I need to make a way for a user to save a sample of an image once a user uploaded image is uploaded onto it.

This means I have to use multiple loaders, right?

So, I can get the bacround image to save just fine. but when I add the container for the logo, I get a reference error. More specifically-

ReferenceError: Error #1069: Property FileName.jpg not found on flash.utils.ByteArray and there is no default value.

Here is my script-

[CODE]

sampleSaveBTN.addEventListener(MouseEvent.CLICK, saveSampleImage);

function saveSampleImage (evt: MouseEvent)

{

var bitmapData:BitmapData = new BitmapData(BGContain.width, BGContain.height);

var logoBitmapData:BitmapData = new BitmapData(logoContain.width, logoContain.height);

bitmapData.draw(BGContain);

logoBitmapData.draw(logoContain);

var jpg:JPGEncoder = new JPGEncoder(100);

var ba:ByteArray = jpg.encode(bitmapData);

var la:ByteArray = jpg.encode(logoBitmapData);

file = new FileReference();

file.save[ba,la, 'FileName.jpg'];

[/CODE]

TOPICS
ActionScript
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 06, 2013 Jan 06, 2013

save is a method (that takes one or two parameters).  you're using it as if it were an array?

Translate
Community Expert ,
Jan 06, 2013 Jan 06, 2013

save is a method (that takes one or two parameters).  you're using it as if it were an array?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 06, 2013 Jan 06, 2013

Thanks for the response!

I changed this to use the byte array as an array. Still getting the same error though. If I leave out all the logoContain script, it works just fine.

function saveSampleImage (evt: MouseEvent)

{

var bitmapData:BitmapData = new BitmapData(BGContain.width, BGContain.height);

var logoBitmapData:BitmapData = new BitmapData(logoContain.width, logoContain.height);

bitmapData.draw(BGContain);

logoBitmapData.draw(logoContain);

var jpg:JPGEncoder = new JPGEncoder(100);

var ba:ByteArray = jpg.encode[bitmapData, logoBitmapData];

file = new FileReference();

file.save(ba,'FileName.jpg');

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2013 Jan 06, 2013

the encode method accepts one bitmapdata object.

what are you trying to do?  are you trying to create one image from two?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 06, 2013 Jan 06, 2013

Yes. I have an external background image that loads into a container and then another image that the user can load in. I can't load both images into the same container because the user loaded image has a filter that needs to be applied.

I just tried gathering the 2 loaders into a sprite, but now when I save an image, it's blank.

Thanks for the help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2013 Jan 06, 2013

you have two different images and you're trying to combine them into one image?  if yes, in what way do you want to combine them?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 06, 2013 Jan 06, 2013

I was able to get it to roughly work with the following:

http://stackoverflow.com/questions/9063990/how-can-i-merge-multiple-bitmapdata-objects-into-one-so-t...

Here is the code- I added the children from the previous containers. Their loader positions are gone, but I feel like I'm on the right track now!

function saveSampleImage (evt: MouseEvent)

{

    var gatherSample: Sprite = new Sprite();

    gatherSample.addChild(bgImgLoader);

    gatherSample.addChild(loadLogo);

    matrix = color.CalculateFinalFlatArray();

    colorMatrix = new ColorMatrixFilter (matrix);

    filterBW = [colorMatrix];

    loadLogo.filters = filterBW;

    var sampleData: BitmapData = new BitmapData(gatherSample.width, gatherSample.height);

   

    sampleData.draw(gatherSample);

var jpg:JPGEncoder = new JPGEncoder(100);

var ba:ByteArray = jpg.encode(sampleData);

file = new FileReference();

file.save(ba,'FileName.jpg' + ".jpg");

}

Thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2013 Jan 06, 2013

that's what i keep asking:  how do you want to combine them?  right now you have them overlapping on top of each other.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 06, 2013 Jan 06, 2013

Yes, They overlap. loadLogo has to be in a specific location. Haven't quite figured that one out though.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2013 Jan 06, 2013

assign their positions:

function saveSampleImage (evt: MouseEvent)

{

    var gatherSample: Sprite = new Sprite();

    gatherSample.addChild(bgImgLoader);

    gatherSample.addChild(loadLogo);

bgImgLoader.y=0;

loadLogo.y=bgImgLoader.height; // if you want them vertically oriented, for example

    matrix = color.CalculateFinalFlatArray();

    colorMatrix = new ColorMatrixFilter (matrix);

    filterBW = [colorMatrix];

    loadLogo.filters = filterBW;

    var sampleData: BitmapData = new BitmapData(gatherSample.width, gatherSample.height);

   

    sampleData.draw(gatherSample);

var jpg:JPGEncoder = new JPGEncoder(100);

var ba:ByteArray = jpg.encode(sampleData);

file = new FileReference();

file.save(ba,'FileName.jpg' + ".jpg");

}

Thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 08, 2013 Jan 08, 2013

awesome thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2013 Jan 08, 2013
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines