Flash AS3色彩校正

时间:2011-06-18 01:39:44

标签: xml flash actionscript-3 actionscript colors

我很快就会需要一顶假发来替换我为此问题而撕掉的头发!我的网站上有一个flash元素,它是一个XML库。它应该与背景无缝融合。我导入了一个具有透明度的PNG,其中一条边是与另一条BG的混合边。当然,Mac和Windows都有颜色变化。我尝试导入PSD,保存为JPG,使用GammaSlamma删除分析,各种各样的东西。

我认为我将不得不手动调整图像以匹配,然后根据用户的操作系统或类似的东西提供两个不同的Flash文件,但后来我看到AS3支持色彩校正,很多人都有似乎觉得它很有用。毋庸置疑,我非常兴奋但是,我以前从未使用过AS3,并且正在开发一个令人头痛的问题。

我发现了一个替代免费幻灯片,它是AS3,但我不知道在哪里添加此代码。

根据http://kelsocartography.com/blog/?tag=as3-color-correction提供的代码就是所需要的:

stage.colorCorrection = ColorCorrection.ON;

图库的代码(抱歉这么长的代码段):

    //----------------------------------------------------------------------------------------------------
//  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

您可以看到我在其中添加了“颜色校正”,但在运行文件时出现此错误:

ReferenceError: Error #1065: Variable stage is not defined.
at global$init()

有什么建议吗?谢谢....

2 个答案:

答案 0 :(得分:2)

这是因为尚未定义/创建舞台。所以这里有两个选项:

  1. 使用ADDED_TO_STAGE侦听器 等待添加幻灯片 到了舞台。所以你要添加 跟随构造函数:

    addEventListener(Event.ADDED_TO_STAGE,
    

    _added);      并将此函数添加到类:

    private _added function(e:Event)
    {
      removeEventListener(Event.ADDED_TO_STAGE,
    

    _added);       stage.colorCorrection = ColorCorrection.ON;     }

  2. 制作一个文件课(见 http://goo.gl/b92SU啧啧 这些对你的闪光灯如此:

    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;
        }
      }
    }
    

答案 1 :(得分:0)

无法将代码放在课堂外。删除行

stage.colorCorrection = ColorCorrection.ON;

并将其放在Document Class构造函数上。如果您遇到问题,则意味着您的应用程序未正确设置。我建议您创建一个新问题,或阅读this tutorial