Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 精灵图层在AS3图形代码中消失_Actionscript 3_Flash_Actionscript - Fatal编程技术网

Actionscript 3 精灵图层在AS3图形代码中消失

Actionscript 3 精灵图层在AS3图形代码中消失,actionscript-3,flash,actionscript,Actionscript 3,Flash,Actionscript,我正在构建一个定制的绘画应用程序,我遇到了一个问题,在添加24层后,我要添加到画布的层消失了 以下是我的绘图工具代码: //===================================================================================================================================== // DRAWING FUNCTIONS //-------------------

我正在构建一个定制的绘画应用程序,我遇到了一个问题,在添加24层后,我要添加到画布的层消失了

以下是我的绘图工具代码:

    //=====================================================================================================================================
    // DRAWING FUNCTIONS
    //-------------------------------------------------------------------------------------------------------------------------------------
    protected function onMouseDown_canvas( evt:MouseEvent ):void
    {
        var p:Point = new Point( _realView.mouseX, _realView.mouseY );

        _log.log( "CanvasViewController :: onMouseDown_canvas() - mouse:" + p );

        _realView.addEventListener( MouseEvent.MOUSE_UP,   onMouseUp_canvas );
        _realView.addEventListener( MouseEvent.MOUSE_OUT,  onMouseOut_canvas );
        _realView.addEventListener( MouseEvent.MOUSE_MOVE, onMouseMove_canvas );

        _currentLayer = new Sprite();
        _currentLayer.mouseEnabled = false;
        _realView.mcContainer.addChild( _currentLayer );

        _$clearFirstBrushStroke = false;

        switch( _$tool )
        {
            case ToolType.ERASER:
            case ToolType.BRUSH:
            case ToolType.PENCIL:
                _currentLayer.graphics.beginFill(
                    ( _$tool == ToolType.ERASER ? 0xffffff : _$color ),
                    ( _$tool == ToolType.BRUSH  ? .4 : 1 )
                );
                _currentLayer.graphics.drawCircle( p.x, p.y, _$toolSize/2 )
                _currentLayer.graphics.endFill();
                _firstPoint = p;
                _$clearFirstBrushStroke = true;
                if( _$tool == ToolType.BRUSH )
                    _currentLayer.filters = [ new BlurFilter( 3, 3, 2 ) ];
                break;
            case ToolType.BRUSH2:
                drawGlitter( _currentLayer.graphics, p );
                break;
        }
    }
    //-------------------------------------------------------------------------------------------------------------------------------------
    protected function onMouseUp_canvas( evt:MouseEvent ):void
    {
        var p:Point = new Point( _realView.mouseX, _realView.mouseY );
        _log.log( "CanvasViewController :: onMouseUp_canvas() - mouse:" + p );
        endDrawing();
    }
    //-------------------------------------------------------------------------------------------------------------------------------------
    protected function onMouseMove_canvas( evt:MouseEvent ):void
    {
        var p:Point = new Point( _realView.mouseX, _realView.mouseY );

        switch( _$tool )
        {
            case ToolType.ERASER:
            case ToolType.BRUSH:
            case ToolType.PENCIL:
                if( _$clearFirstBrushStroke )
                {
                    _$clearFirstBrushStroke = false;
                    _currentLayer.graphics.clear();
                    _currentLayer.graphics.lineStyle( 
                        _$toolSize, 
                        ( _$tool == ToolType.ERASER ? 0xffffff : _$color ),
                        ( _$tool == ToolType.BRUSH  ? .4 : 1 ),
                        true,
                        LineScaleMode.NORMAL,
                        CapsStyle.ROUND,
                        JointStyle.ROUND
                    );
                    _currentLayer.graphics.moveTo( _firstPoint.x, _firstPoint.y );
                }
                _currentLayer.graphics.lineTo( p.x, p.y );
                break;
            case ToolType.BRUSH2:
                drawGlitter( _currentLayer.graphics, p );
                break;
        }
    }
    //-------------------------------------------------------------------------------------------------------------------------------------
    protected function onMouseOut_canvas( evt:MouseEvent ):void
    {
        var p:Point = new Point( _realView.mouseX, _realView.mouseY );
        _log.log( "CanvasViewController :: onMouseOut_canvas() - mouse:" + p );
        endDrawing();
    }
    //-------------------------------------------------------------------------------------------------------------------------------------
    protected function endDrawing():void
    {
        var p:Point = new Point( _realView.mouseX, _realView.mouseY );
        _log.log( "CanvasViewController :: endDrawing() - mouse:" + p );

        _realView.removeEventListener( MouseEvent.MOUSE_UP,   onMouseUp_canvas );
        _realView.removeEventListener( MouseEvent.MOUSE_OUT,  onMouseOut_canvas );
        _realView.removeEventListener( MouseEvent.MOUSE_MOVE, onMouseMove_canvas );

        var bmd:BitmapData = new BitmapData( _realView.width, _realView.height, true, 0x00000000 );
        bmd.draw( _currentLayer );
        var bmp:Bitmap = new Bitmap( bmd, "auto", true );

        _realView.mcContainer.removeChild( _currentLayer );
        _realView.mcContainer.addChild( bmp );

        _currentLayer = null;

        _log.log( "  numChildren:" + _realView.mcContainer.numChildren );
    }
    //-------------------------------------------------------------------------------------------------------------------------------------
    protected function drawGlitter( g:Graphics, c:Point, $glitterSize:Number = 2, $density:Number = .5 ):void
    {
        var $startAngle:Number = NewMath.Random( 0, Math.PI*2 );
        var $stepAngle:Number = $startAngle / ( $density * _$toolSize );

        for( var $i:int = 0; $i < ( $density * _$toolSize ); $i++ )
        {
            var $a:Number = $startAngle + ( $i * $stepAngle );
            var $r:Number = NewMath.Random( 0, _$toolSize / 2 );
            var p:Point = new Point( c.x + Math.cos( $a ) * $r, c.y + Math.sin( $a ) * $r );
            g.beginFill( _$color, 1 );
            g.drawCircle( p.x, p.y, $glitterSize / 2 );
            g.endFill();
        }
    }
//=====================================================================================================================================
//绘图功能
//-------------------------------------------------------------------------------------------------------------------------------------
mousedown_画布上的受保护函数(evt:MouseEvent):void
{
var p:Point=新点(_realView.mouseX,_realView.mouseY);
_log.log(“CanvasViewController::onMouseDown_canvas()-鼠标:”+p);
_addEventListener(MouseEvent.MOUSE\u UP,onMouseUp\u画布);
_addEventListener(MouseEvent.MOUSE\u OUT,onMouseOut\u画布);
_addEventListener(MouseEvent.MOUSE\u MOVE,onMouseMove\u画布);
_currentLayer=新精灵();
_currentLayer.mouseEnabled=false;
_realView.mcContainer.addChild(_currentLayer);
_$clearFirstBrushStroke=false;
开关($tool)
{
case ToolType.橡皮擦:
case ToolType.BRUSH:
case ToolType.PENCIL:
_currentLayer.graphics.beginll(
($tool==ToolType.橡皮擦?0xffffff:$color),
($tool==ToolType.BRUSH?.4:1)
);
_currentLayer.graphics.drawCircle(p.x、p.y、$toolSize/2)
_currentLayer.graphics.endFill();
_第一点=p;
_$clearFirstBrushStroke=true;
if($tool==ToolType.BRUSH)
_currentLayer.filters=[新的模糊过滤器(3,3,2)];
打破
案例工具类型.2:
Drawglite(_currentLayer.graphics,p);
打破
}
}
//-------------------------------------------------------------------------------------------------------------------------------------
mouseup_画布上的受保护函数(evt:MouseEvent):void
{
var p:Point=新点(_realView.mouseX,_realView.mouseY);
_log.log(“CanvasViewController::onMouseUp_canvas()-鼠标:”+p);
endDrawing();
}
//-------------------------------------------------------------------------------------------------------------------------------------
MouseMove_画布上受保护的函数(evt:MouseEvent):void
{
var p:Point=新点(_realView.mouseX,_realView.mouseY);
开关($tool)
{
case ToolType.橡皮擦:
case ToolType.BRUSH:
case ToolType.PENCIL:
如果($clearFirstBrushStroke)
{
_$clearFirstBrushStroke=false;
_currentLayer.graphics.clear();
_currentLayer.graphics.lineStyle(
_$toolSize,
($tool==ToolType.橡皮擦?0xffffff:$color),
($tool==ToolType.BRUSH?.4:1),
符合事实的
LineScaleMode.NORMAL,
卡普斯泰尔,
圆形接头
);
_currentLayer.graphics.moveTo(_firstPoint.x,_firstPoint.y);
}
_currentLayer.graphics.lineTo(p.x,p.y);
打破
案例工具类型.2:
Drawglite(_currentLayer.graphics,p);
打破
}
}
//-------------------------------------------------------------------------------------------------------------------------------------
mouseout_canvas上受保护的函数(evt:MouseEvent):void
{
var p:Point=新点(_realView.mouseX,_realView.mouseY);
_log.log(“CanvasViewController::onMouseOut_canvas()-鼠标:”+p);
endDrawing();
}
//-------------------------------------------------------------------------------------------------------------------------------------
受保护的函数endDrawing():void
{
var p:Point=新点(_realView.mouseX,_realView.mouseY);
_log.log(“CanvasViewController::endDrawing()-鼠标:”+p);
_removeEventListener(MouseEvent.MOUSE\u UP,onMouseUp\u画布);
_removeEventListener(MouseEvent.MOUSE\u OUT,onMouseOut\u画布);
_removeEventListener(MouseEvent.MOUSE\u MOVE,onMouseMove\u canvas);
var bmd:BitmapData=新的BitmapData(_realView.width,_realView.height,true,0x00000000);
bmd.draw(_currentLayer);
var bmp:Bitmap=新位图(bmd,“自动”,真);
_realView.mcContainer.removeChild(_currentLayer);
_realView.mcContainer.addChild(bmp);
_currentLayer=null;
_log.log(“numChildren:+\u realView.mcContainer.numChildren);
}
//-------------------------------------------------------------------------------------------------------------------------------------
受保护的函数drawgliter(g:Graphics,c:Point,$glitersize:Number=2,$density:Number=0.5):无效
{
var$startAngle:Number=NewMath.Random(0,Math.PI*2);
变量$stepAngle:Number=$startAngle/($density*$toolSize);
对于(变量$i:int=0;$i<($density*$toolSize);$i++)
{
变量$a:Number=$startAngle+($i*$stepAngle);
var$r:Number=NewMath.Random(0,$toolSize/2);
var p:Point=新点(c.x+数学cos($a)*$r,c.y+数学sin($a)*$r);
g、 beginull($color,1);
g、 拉丝圈(p.x,p.y.$尺寸/2);
g、 endFill();
}
}
孩子们继续成长,但一旦我