Flash AS3 Color Correction
I will soon need a wig to replace the hair I've ripped out in regards to this problem! I have a flash element on my website that is an XML gallery. It's supposed to blend seamlessly in with the background. I imported a PNG that has transparency which one edge is the blending edge with the other BG. Of course there's a color shift on both Mac and Windows. I tried importing PSD, saving as JPG, using GammaSlamma to remove profiling, all sorts of stuff.
I thought I was going to have to manually adjust the image to match and then serve two different Flash files depending on the user's OS or something crazy like that, but then I saw that AS3 supports color correction and a lot of people have seemed to find it useful. Needless to say I was very excited However, I've NEVER used AS3 before, and am developing a major headache over it.
I found a replacement free slideshow that's AS3 but I just have no idea where to add this code in.
Code that according to http://kelsocartography.com/blog/?tag=as3-color-correction is all that's needed:
stage.colorCorrection = ColorCorrection.ON;
The code for the gallery (sorry for such a long snippet):
//----------------------------------------------------------------------------------------------------
// XMLSlideshow.as
// 19 Feb 2009
// www.simplistika.com
//----------------------------------------------------------------------------------------------------
package com.simplistika
{
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
import flash.utils.Timer;
//Color correction
import flash.display.ColorCorrection;
stage.colorCorrection = ColorCorrection.ON;
//----------------------------------------------------------------------------------------------------
// class definition
//----------------------------------------------------------------------------------------------------
public class XMLSlideshow extends cXMLApp
{
//----------------------------------------------------------------------------------------------------
// member data
//----------------------------------------------------------------------------------------------------
private var mTimer : Timer;
private var mPlaceholder1 : Loader = new Loader();
private var mPlaceholder2 : Loader = new Loader();
private var mControl : mcControl = new mcControl();
private var mSlide : int;
//----------------------------------------------------------------------------------------------------
// slideshow setup
//----------------------------------------------------------------------------------------------------
private var mFile : String = "http://www.simplistika.com/files/ssp/Slideshow.xml"; // path to xml file
private var mInterval : uint = 8000; // slide interval
//----------------------------------------------------------------------------------------------------
// constructor
//----------------------------------------------------------------------------------------------------
public function
XMLSlideshow(
) : void
{
trace(this + " " + "XMLSlideshow.constructor");
mTimer = new Timer(mInterval, 0);
mPlaceholder1.contentLoaderInfo.addEventListener(Event.OPEN, fOpen);
mPlaceholder1.contentLoaderInfo.addEventListener(Event.COMPLETE, fResult);
mPlaceholder2.contentLoaderInfo.addEventListener(Event.OPEN, fOpen);
mPlaceholder2.contentLoaderInfo.addEventListener(Event.COMPLETE, fResult);
//this.addEventListener(MouseEvent.MOUSE_OVER, fOnMouseOver);
//this.addEventListener(MouseEvent.MOUSE_OUT, fOnMouseOut);
//this.addEventListener(MouseEvent.CLICK, fOnClick);
mTimer.addEventListener(TimerEvent.TIMER, fTimer);
addChild(mPlaceholder1);
addChild(mPlaceholder2);
addChild(mControl);
mSlide = 0;
mControl.btnForward.alpha = mControl.btnBack.alpha = mControl.btnPause.alpha = 0.0;
//mControl.btnForward.buttonMode = mControl.btnBack.buttonMode = mControl.btnPause.buttonMode = true;
mControl.btnForward.visible = mControl.btnBack.visible = false;
super(mFile);
super.addEventListener("XMLLoaded", fStart);
}
//----------------------------------------------------------------------------------------------------
// fStart
//----------------------------------------------------------------------------------------------------
private function
fStart(
e : Event
) : void
{
trace(this + " " + "XMLSlideshow.fStart");
fLoadImage();
}
//----------------------------------------------------------------------------------------------------
// fOnMouseOver
//----------------------------------------------------------------------------------------------------
/* private function
fOnMouseOver(
e : MouseEvent
) : void
{
switch (e.target.name)
{
case "btnPause":
mTimer.running ? mControl.txtDesc.text = "Pause" : mControl.txtDesc.text = "Play";
break;
case "btnForward":
mControl.txtDesc.text = "Next";
break;
case "btnBack":
mControl.txtDesc.text = "Back";
break;
default:
return;
}
mControl.txtDesc.alpha = 1;
e.target.alpha = 0.7;
}
//----------------------------------------------------------------------------------------------------
// fOnMouseOut
//----------------------------------------------------------------------------------------------------
private function
fOnMouseOut(
e : MouseEvent
) : void
{
switch (e.target.name)
{
case "btnPause":
case "btnForward":
case "btnBack":
e.target.alpha = 0.5;
mControl.txtDesc.alpha = 0;
return;
}
}
//----------------------------------------------------------------------------------------------------
// fOnClick
//----------------------------------------------------------------------------------------------------
private function
fOnClick(
e : MouseEvent
) : void
{
trace(this + " " + "XMLSlideshow.fOnClick " + e.target.name);
switch (e.target.name)
{
case "btnPause":
if (mControl.txtDesc.text == "Pause")
{
mTimer.stop();
开发者_开发知识库 mControl.btnBack.visible = mControl.btnForward.visible = true;
mControl.txtDesc.text = "Play";
}
else
{
mTimer.start();
mControl.btnBack.visible = mControl.btnForward.visible = false;
mControl.txtDesc.text = "Pause";
}
return;
case "btnForward":
mSlide == mItems - 1 ? mSlide = 0 : mSlide++;
break;
case "btnBack":
mSlide == 0 ? mSlide = mItems - 1 : mSlide--;
break;
default:
return;
}
fLoadImage();
} */
//----------------------------------------------------------------------------------------------------
// fLoadImage
//----------------------------------------------------------------------------------------------------
private function
fLoadImage(
) : void
{
getChildIndex(mPlaceholder1) != 0 ?
mPlaceholder2.load(new URLRequest(mData.slide[mSlide].url)) :
mPlaceholder1.load(new URLRequest(mData.slide[mSlide].url));
}
//----------------------------------------------------------------------------------------------------
// fTimer
//----------------------------------------------------------------------------------------------------
private function
fTimer(
e : TimerEvent
) : void
{
mSlide == mItems - 1 ? mSlide = 0 : mSlide++;
fLoadImage();
}
//----------------------------------------------------------------------------------------------------
// fOpen
//----------------------------------------------------------------------------------------------------
private function
fOpen(
e : Event
) : void
{
mTimer.stop();
}
//----------------------------------------------------------------------------------------------------
// fResult
//----------------------------------------------------------------------------------------------------
private function
fResult(
e : Event
) : void
{
if (!mControl.btnForward.visible)
mTimer.start();
getChildIndex(mPlaceholder1) == 0 ? fNextImage(mPlaceholder1) : fNextImage(mPlaceholder2);
}
//----------------------------------------------------------------------------------------------------
// fKenBurns
//----------------------------------------------------------------------------------------------------
private function
fNextImage(
vPlaceholder : Loader
) : void
{
setChildIndex(vPlaceholder, this.numChildren - 2);
vPlaceholder.alpha = 0;
vPlaceholder == mPlaceholder1 ? cTween.to(mPlaceholder2, {alpha:0}, 1) : cTween.to(mPlaceholder1, {alpha:0}, 1);
cTween.to(vPlaceholder, { alpha:1 }, 1);
}
//----------------------------------------------------------------------------------------------------
} // class
//----------------------------------------------------------------------------------------------------
} // package
You can see I added "color correction" in there, but get this error when I run the file:
ReferenceError: Error #1065: Variable stage is not defined.
at global$init()
Any suggestions? Thank you....
That's because the stage is not defined/created yet. So here are 2 options:
Use the ADDED_TO_STAGE listener to wait for the slideshow to be added to the stage. So you'd have add the following to the constructor:
addEventListener(Event.ADDED_TO_STAGE,
_added); And add this function to the class:
private _added function(e:Event) { removeEventListener(Event.ADDED_TO_STAGE,
_added); stage.colorCorrection = ColorCorrection.ON; }
Make a document class (see http://goo.gl/b92SU for a tut on these) for your flash like so:
package { import flash.display.MovieClip; public class Main extends MovieClip { function Main() { addEventListener(Event.ADDED_TO_STAGE, _added); //other code that was in your main timeline } private function _added(e:Event):void { removeEventListener(Event.ADDED_TO_STAGE, _added); stage.colorCorrection = ColorCorrection.ON; } } }
You can't put code outside a class. Remove the line
stage.colorCorrection = ColorCorrection.ON;
And place it on your Document Class constructor. If you have trouble with that, means that your application is not properly set. I'd recommend you to create a new question, or read this tutorial.
精彩评论