externally loaded image disappears??
In my swf, the user can upload and image and edit it. The can move and scale the image.
When I test this in flash, it works great. But, when I try it out on the testing server, it works ok for about 8 seconds and then if you try to do anything to the image after that, the image disappears which is not good.
Below is all the script that drives this. Not sure what the problem is.
var isMetal:String = loaderInfo.parameters.isMetal;
//Handles Image Logo Upload
//filter image types that can be uploaded
var logoLoaded: Boolean;
var file:FileReference = new FileReference();
var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");
var allTypes : Array = new Array(imageTypes);
file.addEventListener(Event.SELECT, fileSelect);
file.addEventListener(Event.COMPLETE, fileComplete);
UploadBTN.addEventListener(MouseEvent.CLICK, UploadImage);
UploadBTN.buttonMode = true;
UploadBTN.useHandCursor = true;
UploadBTN.mouseChildren = true;
function UploadImage(event:MouseEvent):void
{
file.browse(allTypes);
}
function fileSelect(event:Event){
file.addEventListener(Event.COMPLETE, fileComplete);
file.addEventListener(IOErrorEvent.IO_ERROR, fileLoadError);
file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
file.load();
}
function fileLoadError(event:Event):void
{
trace("File load error");
}
function progressHandler (event: ProgressEvent): void
{
var file:FileReference = FileReference(event.target);
var percentLoaded:Number=event.bytesLoaded/event.bytesTotal*100;
trace("loaded: "+percentLoaded+"%");
}
//***places logo on stage and changes logo color once image upload is complete***
var shader:Shader = new Shader(new RemoveWhiteBGKernel() );
var shaderFilter:ShaderFilter = new ShaderFilter( shader );
var loadLogo:Loader = new Loader();
var colorMatrix : ColorMatrixFilter = new ColorMatrixFilter;
var color : AdjustColor = new AdjustColor;
var matrix : Array = new Array;
var filterBW : Array = new Array;
function fileComplete(event:Event): void
{
//filter properties to make logo look like etched glass
if(isMetal == "false")
{
color = new AdjustColor();
color.brightness = 100;
color.contrast = 50;
color.hue = 0;
color.saturation = -100;
}
else
{
color = new AdjustColor();
color.brightness = 0;
color.contrast = 10;
color.hue = 0;
color.saturation = -100;
}
//applies filter to logo
loadLogo.loadBytes(file.data);
matrix = color.CalculateFinalFlatArray();
colorMatrix = new ColorMatrixFilter (matrix);
filterBW = [colorMatrix];
loadLogo.filters = [shaderFilter];
loadLogo.filters = filterBW;
logoLoaded = true;
loadLogo.rotationX = 0;
loadLogo.rotationZ = 0;
loadLogo.rotationY = 0;
Bitmap(loadLogo.content).smoothing = true;
}
//sets registration to center position
loadLogo.contentLoaderInfo.addEventListener(Event.INIT,onLoaderInit);
var container: Sprite = new Sprite();
function onLoaderInit(event: Event): void
{
container.addChild(loadLogo);
BGContain.addChild(container);
loadLogo.x = loadLogo.width/ -2;
loadLogo.y = loadLogo.height/ -2;
container.x = container.width/2 + 125;
container.y = container.height/2 + 25;
loadLogo.filters = [shaderFilter];
container.filters = filterBW;
container.scaleX = loadLogo.scaleX;
container.scaleY = loadLogo.scaleY;
container.buttonMode = true;
container.useHandCursor = true;
}
//Image Adjustments
import flash.events.MouseEvent;
import flash.geom.Rectangle;
logoScaleSlider.value = 1;
logoRotateX.value = 0;
logoRotateY.value = 0;
logoRotateZ.value = 0;
container.scaleX = 1;
container.scaleY = 1;
container.rotationX = 0;
container.rotationY = 0;
container.rotationZ = 0;
logoPosX.text = "Logo Scale: 0"
logoRotX.text = "Rotate X: 0"
logoRotY.text = "Rotate Y: 0"
logoRotZ.text = "Rotate Z: 0"
//scale logo slider
var scaleTxtMC: MovieClip = new MovieClip();
logoPosX.text = "Logo Scale: 0"
addChild(logoPosX);
logoScaleSlider.value = 1;
logoScaleSlider.addEventListener(SliderEvent.CHANGE, logoChangeScale);
function logoChangeScale (event:SliderEvent): void
{
logoPosX.text = "Logo Scale: " + event.target.value;
container.scaleX = event.target.value / 20;
container.scaleY = event.target.value / 20;
}
//rotate logo around the X axis
logoRotX.text = "Rotate X: 0"
logoRotateX.value = 1;
logoRotateX.addEventListener(SliderEvent.CHANGE, logoRotateXPos);
function logoRotateXPos (event:SliderEvent): void
{
logoRotX.text = "Rotate X: " + event.target.value;
container.scaleX = event.target.value / 20;
}
//rotate logo around the Y axis
logoRotY.text = "Rotate Y: 0"
logoRotateY.value = 1;
logoRotateY.addEventListener(SliderEvent.CHANGE, logoRotateYPos);
function logoRotateYPos (event:SliderEvent): void
{
logoRotY.text = "Rotate Y: " + event.target.value;
container.scaleY = event.target.value / 20;
}
//rotate logo around the Z axis
logoRotateZ.value = 1;
logoRotateZ.addEventListener(SliderEvent.CHANGE, logoRotateZPos);
function logoRotateZPos (event:SliderEvent): void
{
logoRotZ.text = "Rotate Z: " + event.target.value;
container.rotationZ = event.target.value;
}
positionText.text = "Precise Position with Arrows";
logoUpBTN.addEventListener(MouseEvent.CLICK, moveLogoUp)
logoUpBTN.buttonMode = true;
logoUpBTN.useHandCursor = true;
function moveLogoUp(evt: MouseEvent)
{
container.y -= 2;
}
rightMoveBTN.addEventListener(MouseEvent.CLICK, moveLogoRight)
rightMoveBTN.buttonMode = true;
rightMoveBTN.useHandCursor = true;
function moveLogoRight(evt: MouseEvent)
{
container.x += 2;
}
moveLeftBTN.addEventListener(MouseEvent.CLICK, moveLogoLeft)
moveLeftBTN.buttonMode = true;
moveLeftBTN.useHandCursor = true;
function moveLogoLeft(evt: MouseEvent)
{
container.x -= 2;
}
moveDownBTN.addEventListener(MouseEvent.CLICK, moveLogoDown)
moveDownBTN.buttonMode = true;
moveDownBTN.useHandCursor = true;
function moveLogoDown(evt: MouseEvent)
{
container.y += 2;
}
//Clear Image
clearBTN.addEventListener(MouseEvent.CLICK, clearLogo);
clearBTN.buttonMode = true;
clearBTN.useHandCursor = true;
function clearLogo (evt:MouseEvent)
{
if (logoLoaded == true)
{
BGContain.removeChild(container);
logoLoaded = false;
logoScaleSlider.value = 1;
logoRotateX.value = 0;
logoRotateY.value = 0;
logoRotateZ.value = 0;
container.scaleX = 1;
container.scaleY = 1;
container.rotationX = 0;
container.rotationY = 0;
container.rotationZ = 0;
logoPosX.text = "Logo Scale: 1";
logoRotX.text = "Rotate X: 0"
logoRotY.text = "Rotate Y: 0"
logoRotZ.text = "Rotate Z: 0"
container.x = container.width/2 + 125;
container.y = container.height/2 + 25;
}
else
{
throw new Error ('You have not uploaded a logo or art work.');
}
}
//drag and drop functionality
var limitDragX: int = BGContain.width;
var limitDragY: int = BGContain.height;
var dragWidth: int = 0 - limitDragX;
var dragHeight: int = 0 - limitDragY;
var dragBoundary: Rectangle = new Rectangle(limitDragX, limitDragY, dragWidth, dragHeight);
container.addEventListener(MouseEvent.MOUSE_DOWN, drag);
container.addEventListener(MouseEvent.MOUSE_UP, drop);
function drag(event:MouseEvent):void
{
container.startDrag(false,dragBoundary);
}
function drop(event:MouseEvent):void
{
container.stopDrag();
}
resetImgBTN.addEventListener(MouseEvent.CLICK,resetLogo);
resetImgBTN.buttonMode = true;
resetImgBTN.useHandCursor = true;
function resetLogo(evt:MouseEvent):void
{
logoScaleSlider.value = 1;
logoRotateX.value = 0;
logoRotateY.value = 0;
logoRotateZ.value = 0;
container.scaleX = 1;
container.scaleY = 1;
container.rotationX = 0;
container.rotationY = 0;
container.rotationZ = 0;
logoPosX.text = "Logo Scale: 1";
logoRotX.text = "Rotate X: 0"
logoRotY.text = "Rotate Y: 0"
logoRotZ.text = "Rotate Z: 0"
container.x = container.width/2 + 125;
container.y = container.height/2 + 25;
}
