Explorer
02-12-2008, 11:54 AM
Hi!
I've been a flash AS developer for many years. Once AS3 came out I was pretty exited, but I just couldn't handle it at that moment, so I just kept writing in AS2. Didn't have much time to learn how to migrate. But now I'm forced to work with AS3 and AIR and I've run into some problems. I've been looking for answers and I was looking for so long that I've just run out of time and I need your assistance immediately my friends.
Short project description: 2D tracker application.
Stage of development: Importing image sequence by drag&drop
Problem description:
I have a regular slider component as a timeline. Max value of the slider is being set to the amount of files dropped. Heres the code:
function doDragDrop(e:NativeDragEvent):void{
var fileList:Object = e.clipboard.getData(ClipboardFormats.FILE_LIST_FOR MAT);
objProject.fileList = fileList;
movSeekBar.maximum = fileList.length-1;
}
Easy so far. Now I add an event listener to the slider to determine which file of the objProject.fileList should be displayed. The event calls renderFrame() function. Heres the code.
function renderFrame(){
var currentFrame:Number = new Number(movSeekBar.value);
var currentFileName:String = new String(objProject.fileList[currentFrame].url)
var currentFile:File = new File(currentFileName);
var loadImage:Loader = new Loader();
loadImage.load(new URLRequest(currentFileName));
addChild(loadImage);
}
This code works, but not totally the way I'd like it to. When invoking addChild it adds the image file to the "_root". I want it to be put into one of the movieclips that are placed on the stage during design-time. The instance name for that movieclip is movDisplay.
When I use movDisplay.addChild(loadImage) something happens. The movieclip becomes black, but I don't see the image.
That's not the only problem. I understand that invoking addChild when I
scrub through the timeline (slider) it constantly adds new childs.
That's a huge memory leak. The current frame (displayed image) could
be replaced with the new one once I scrub.
Also, I need access to pixel informations of the current rendered frame, so I could perform the 2d point tracking.
Summary:
1) how do I load and external image file to a movieclip that is placed on the stage during design-time?
2) how do I keep replacing the image instead of creating new ones on top of it?
3) how do I gain easy access to the pixel informations?
I once did something simmilar (in terms of loading image sequences) in AS2,
but moving that to AS3 is a bit over my head at this point. AS3 is generally a bit over my head. At least for now. I hope that someone could explain this all to me in simplest ways possible. Ready-to-use code would be much appreciated.
Thanks in advance
All the best
I've been a flash AS developer for many years. Once AS3 came out I was pretty exited, but I just couldn't handle it at that moment, so I just kept writing in AS2. Didn't have much time to learn how to migrate. But now I'm forced to work with AS3 and AIR and I've run into some problems. I've been looking for answers and I was looking for so long that I've just run out of time and I need your assistance immediately my friends.
Short project description: 2D tracker application.
Stage of development: Importing image sequence by drag&drop
Problem description:
I have a regular slider component as a timeline. Max value of the slider is being set to the amount of files dropped. Heres the code:
function doDragDrop(e:NativeDragEvent):void{
var fileList:Object = e.clipboard.getData(ClipboardFormats.FILE_LIST_FOR MAT);
objProject.fileList = fileList;
movSeekBar.maximum = fileList.length-1;
}
Easy so far. Now I add an event listener to the slider to determine which file of the objProject.fileList should be displayed. The event calls renderFrame() function. Heres the code.
function renderFrame(){
var currentFrame:Number = new Number(movSeekBar.value);
var currentFileName:String = new String(objProject.fileList[currentFrame].url)
var currentFile:File = new File(currentFileName);
var loadImage:Loader = new Loader();
loadImage.load(new URLRequest(currentFileName));
addChild(loadImage);
}
This code works, but not totally the way I'd like it to. When invoking addChild it adds the image file to the "_root". I want it to be put into one of the movieclips that are placed on the stage during design-time. The instance name for that movieclip is movDisplay.
When I use movDisplay.addChild(loadImage) something happens. The movieclip becomes black, but I don't see the image.
That's not the only problem. I understand that invoking addChild when I
scrub through the timeline (slider) it constantly adds new childs.
That's a huge memory leak. The current frame (displayed image) could
be replaced with the new one once I scrub.
Also, I need access to pixel informations of the current rendered frame, so I could perform the 2d point tracking.
Summary:
1) how do I load and external image file to a movieclip that is placed on the stage during design-time?
2) how do I keep replacing the image instead of creating new ones on top of it?
3) how do I gain easy access to the pixel informations?
I once did something simmilar (in terms of loading image sequences) in AS2,
but moving that to AS3 is a bit over my head at this point. AS3 is generally a bit over my head. At least for now. I hope that someone could explain this all to me in simplest ways possible. Ready-to-use code would be much appreciated.
Thanks in advance
All the best