Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One way to avoid your problem with the infinite loop is to put your animateCursor code inside an ENTER_FRAME event handler.</p> <p>Here's how it can look: <a href="http://www.swfcabin.com/open/1360303185" rel="nofollow">http://www.swfcabin.com/open/1360303185</a></p> <p>( Your custom cursor shape looks awesome ; )</p> <p>Here's your code remade in MiniBuilder ( functions are arranged alphabetically ):</p> <pre><code>package com.glowingcursor { import flash.display.*; import flash.events.*; import flash.geom.*; import flash.ui.*; public class Application extends Sprite { private var cursor:Sprite; private var cursorOffset:Point; private var sense:Boolean; public function Application() { addEventListener( Event.ADDED_TO_STAGE, onAdded ); } private function animateCursor( e:Event ):void { if ( cursor.alpha &gt;= 1 ) sense = false; else if ( cursor.alpha &lt;= 0.2 ) sense = true; if( sense ) cursor.alpha += 0.08; else cursor.alpha -= 0.08; } private function hideCursor( e:MouseEvent ):void { Mouse.show(); removeChild( cursor ); removeEventListener( Event.ENTER_FRAME, moveCursor ); removeEventListener( Event.ENTER_FRAME, animateCursor ); } private function initCursor():void { cursor = new Sprite(); cursor.graphics.beginFill( 0xff0000 ); cursor.graphics.drawRect( 0, 0, 6, 2 ); // top left cursor.graphics.drawRect( 0, 23, 6, 2 ); // bottom left cursor.graphics.drawRect( 0, 0, 2, 6 ); // left top cursor.graphics.drawRect( 0, 19, 2, 6 ); // left bottom cursor.graphics.drawRect( 19, 0, 6, 2 ); // top right cursor.graphics.drawRect( 23, 0, 2, 6 ); // right top cursor.graphics.drawRect( 19, 23, 6, 2 ); // bottom right cursor.graphics.drawRect( 23, 19, 2, 6 ); // right bottom cursor.graphics.endFill(); // So InteractiveObjects react to the custom cursor properly cursor.mouseEnabled = false; // For cursor centering cursorOffset = new Point( cursor.width / 2, cursor.height / 2 ); } private function moveCursor( e:Event ):void { cursor.x = mouseX - cursorOffset.x; cursor.y = mouseY - cursorOffset.y; } private function onAdded( e:Event ):void { initCursor(); showCursor(); } private function showCursor():void { Mouse.hide(); addChild( cursor ); addEventListener( Event.ENTER_FRAME, moveCursor ); addEventListener( Event.ENTER_FRAME, animateCursor ); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload