konami code in flex - actionscript-3

What would be the best way to implement the konami code into a flex application?
I want to create a component to add it on all my proyects, just for fun.
thanks
UPDATE: I made a simple component, thanks to ZaBlanc
<?xml version="1.0" encoding="utf-8"?>
<mx:UIComponent xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Metadata>
[Event(name="success", type="flash.events.Event")]
</mx:Metadata>
<mx:Script>
<![CDATA[
// up-up-down-down-left-right-left-right-B-A
public static const KONAMI_CODE:String = "UUDDLRLRBA";
// signature
private var signatureKeySequence:String = "";
private function init():void{
systemManager.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
private function onKeyDown(event:KeyboardEvent):void{
var keyCode:int = event.keyCode;
switch (keyCode) {
case Keyboard.UP:
signatureKeySequence += "U";
break;
case Keyboard.DOWN:
signatureKeySequence += "D";
break;
case Keyboard.LEFT:
signatureKeySequence += "L";
break;
case Keyboard.RIGHT:
signatureKeySequence += "R";
break;
case 66: //Keyboard.B only for AIR :/
signatureKeySequence += "B";
break;
case 65: //Keyboard.A only for AIR too :(
signatureKeySequence += "A";
break;
default:
signatureKeySequence = "";
break;
}
// crop sequence
signatureKeySequence = signatureKeySequence.substr(0, KONAMI_CODE.length);
// check for konami code
if (signatureKeySequence == KONAMI_CODE) {
dispatchEvent(new Event("success"));
signatureKeySequence = "";
}
}
]]>
</mx:Script>
</mx:UIComponent>
to test it
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:konamicode="konamicode.*">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
]]>
</mx:Script>
<konamicode:KonamiCodeCatch success="Alert.show('+30 lives!!!')" />
</mx:Application>

A state machine is fun to write, but in this case I'd go with a signature pattern. Depending on where you want to put the handler (on the stage of the component), here's some code that should work, though you can probably tighten it (and of course customize it to your specific need):
// up-up-down-down-left-right-left-right-B-A
public static const KONAMI_CODE:String = "UUDDLRLRBA";
// signature
private var signatureKeySequence:String = "";
private function onKeyDown(event:KeyboardEvent):void {
var keyCode:int = event.keyCode;
switch (keyCode) {
case Keyboard.UP:
signatureKeySequence += "U";
break;
case Keyboard.DOWN:
signatureKeySequence += "D";
break;
case Keyboard.LEFT:
signatureKeySequence += "L";
break;
case Keyboard.RIGHT:
signatureKeySequence += "R";
break;
case Keyboard.B:
signatureKeySequence += "B";
break;
case Keyboard.A:
signatureKeySequence += "A";
break;
default:
signatureKeySequence = "";
break;
}
// crop sequence
signatureKeySequence = signatureKeySequence.substr(0, KONAMI_CODE.length);
// check for konami code
if (signatureKeySequence == KONAMI_CODE) {
// 30 lives!
}
}

You may use Casalib. There are classes, Key and KeyCombo. You may listen for KeyComboEvent.SEQUENCE.
Working sample:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init();">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import org.casalib.events.KeyComboEvent;
import org.casalib.ui.Key;
import org.casalib.ui.KeyCombo;
import org.casalib.util.StageReference;
private const KONAMI_CODE:KeyCombo = new KeyCombo([Keyboard.UP,Keyboard.UP,Keyboard.DOWN,Keyboard.DOWN,Keyboard.LEFT,Keyboard.RIGHT,Keyboard.LEFT,Keyboard.RIGHT,("B").charCodeAt(),("A").charCodeAt()]);
private function init():void {
StageReference.setStage(this.systemManager.stage);
Key.getInstance().addKeyCombo(KONAMI_CODE);
Key.getInstance().addEventListener(KeyComboEvent.SEQUENCE,onKonami);
}
private function onKonami(evt:KeyComboEvent):void {
if (evt.keyCombo == KONAMI_CODE){
Alert.show("You know Konami code?","WOW");
}
}
]]>
</mx:Script>
</mx:Application>

var unlockCode:Array = new Array(38,38,40,40,37,39,37,39,66,65,13);
var keyPressArray:Array = new Array();
stage.addEventListener(KeyboardEvent.KEY_DOWN, checkUnlockCode);
function checkUnlockCode(e:KeyboardEvent):void {
if (keyPressArray.length >= unlockCode.length) {
keyPressArray.splice(0,1);
keyPressArray.push(e.keyCode.toString());
} else {
keyPressArray.push(e.keyCode.toString());
}
trace(keyPressArray);
if (keyPressArray.toString() == unlockCode.toString()) {
trace(unlockCode);
}
}

Related

Arrow keys not detected once the SWF file is published

I'm using flash CS4 to have an animated character moving within the stage boundaries. There are no code errors when generating the SWF file and the character is moving fine when I test the movie in Flash. Once I publish the file, the character is completely unresponsive to the arrow keys. I have no clue as what the issue might be and some help would be greatly appreciated. Here's the code of the movie :
stop();
var upPressed:Boolean = false;
var downPressed:Boolean = false;
var leftPressed:Boolean = false;
var rightPressed:Boolean = false;
var isWalking:Boolean = false;
var mySpeed:Number = 3;
my_Sprite.addEventListener(Event.ENTER_FRAME, moveSprite);
stage.addEventListener(KeyboardEvent.KEY_DOWN, setKeyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, unsetKeyPressed);
function moveSprite(event:Event):void {
if(upPressed && my_Sprite.y >= 40){
my_Sprite.y -= mySpeed;
}
if(downPressed && my_Sprite.y <= 440){
my_Sprite.y += mySpeed;
}
if(leftPressed && my_Sprite.x >= 20){
my_Sprite.x -= mySpeed;
}
if(rightPressed && my_Sprite.x <= 600){
my_Sprite.x += mySpeed;
}
}
function setKeyPressed(event:KeyboardEvent):void {
switch(event.keyCode){
case Keyboard.UP: {
upPressed = true;
if (!isWalking) {
my_Sprite.gotoAndPlay("Up");
isWalking = true;
}
break;
}
case Keyboard.DOWN: {
downPressed = true;
if (!isWalking) {
my_Sprite.gotoAndPlay("Down");
isWalking = true;
}
break;
}
case Keyboard.LEFT: {
leftPressed = true;
if (!isWalking) {
my_Sprite.gotoAndPlay("Left");
isWalking = true;
}
break;
}
case Keyboard.RIGHT: {
rightPressed = true;
if (!isWalking) {
my_Sprite.gotoAndPlay("Right");
isWalking = true;
}
break;
}
}
}
function unsetKeyPressed(event:KeyboardEvent):void {
switch(event.keyCode) {
case Keyboard.UP: {
upPressed = false;
my_Sprite.gotoAndStop("Up");
isWalking = false;
break;
}
case Keyboard.DOWN: {
downPressed = false;
my_Sprite.gotoAndStop("Down");
isWalking = false;
break;
}
case Keyboard.LEFT: {
leftPressed = false;
my_Sprite.gotoAndStop("Left");
isWalking = false;
break;
}
case Keyboard.RIGHT: {
rightPressed = false;
my_Sprite.gotoAndStop("Right");
isWalking = false;
break;
}
}
}
You may need to add some JavaScript to your HTML to set the focus on the Flash object:
<body onLoad="window.document.movieID.focus();">
Make sure you change movieID to whatever you actually set as your ID.
you can force the focus by doing
this.stage.focus = myTextField; // assuming this is added to the display hierarchy

How create border in stage

I need advice, please. I'm working on one project - a simple game. It will be something like "Space Invaders". I just needed to cater to the ship could not leave the area (Stage). Function, is called "RMimoXY" does not work. Could someone please check out what I'm missing in the program?
Thanks in advance for your advice.
import flash.events.KeyboardEvent;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.media.Sound;
import flash.display.Stage;
var let: Boolean = false;
var pozadi: Stage;
var vx:Number = 0;
var vy:Number = 0;
function mezernik(){
var mySound: Sound = new laserFire();
mySound.play();
RMimoXY();
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, klavesnice);
function klavesnice(e: KeyboardEvent){
switch(e.keyCode){
case Keyboard.LEFT: lod.x += -5; break;
case Keyboard.RIGHT: lod.x += 5; break;
case Keyboard.UP: lod.y += -5; break;
case Keyboard.DOWN: lod.y += 5; break;
case Keyboard.SPACE: mezernik(); break;
}
}
function RMimoXY(){
if (lod.x > stage.stageWidth ){
lod.x = 0 - lod.width;
}
else if (lod.x < 0 - lod.width ){
lod.x = stage.stageWidth;
}
if (lod.y > stage.stageHeight ){
lod.y = 0 - lod.height;
}
else if (lod.y < 0 - lod.height ){
lod.y = stage.stageHeight;
}
}
It appears as if you're only calling RMimoXY in your constructor. You should call it every time the ship is moved. So adding it to the end of your keyhandler should work:
function klavesnice(e: KeyboardEvent){
switch(e.keyCode){
case Keyboard.LEFT: lod.x += -5; break;
case Keyboard.RIGHT: lod.x += 5; break;
case Keyboard.UP: lod.y += -5; break;
case Keyboard.DOWN: lod.y += 5; break;
case Keyboard.SPACE: mezernik(); break;
}
RMimoXY();
}

ActionScript: How come i cant draw diagonally?

So, I'm learning ActionScript on my own with a book ('Foundation AS3.0 with Flash...').
And I'm stuck on an excercise.
I have to make a drawing app with using the arrowkeys and spacebar.
It doesn't work 100%. I can draw up, down, right, left. Even diagonal, only right-up, and left-down.
Do you guys know where my mistake is? I also want to draw left-up and right-down....
Here's my code so far:
package classes{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.Event;
public class KeyboardDrawing extends Sprite{
private const PIXEL_DISTANCE_TO_DRAW:uint = 2;
private var _canvas:Sprite;
private var _crosshair:Shape;
private var _xDirection:int = 0;
private var _yDirection:int = 0;
private var _isDrawing:Boolean = false;
public function KeyboardDrawing(){
_canvas=new Sprite();
addChild(_canvas);
_crosshair=new Shape();
drawCrosshair();
addChild(_crosshair);
_canvas.graphics.lineStyle(2, 0x000000);
stage.focus=_canvas;
_canvas.addEventListener(KeyboardEvent.KEY_DOWN, onCanvasKeyDown);
_canvas.addEventListener(KeyboardEvent.KEY_UP, onCanvasKeyUp);
_canvas.addEventListener(Event.ENTER_FRAME, onCanvasEnterFrame);
}
private function drawCrosshair():void{
_crosshair.graphics.lineStyle(1, 0x000000);
_crosshair.graphics.moveTo(-5, 0);
_crosshair.graphics.lineTo(6, 0);
_crosshair.graphics.moveTo(0, -5);
_crosshair.graphics.lineTo(0, 6);
}
private function onCanvasKeyDown(event:KeyboardEvent):void{
switch(event.keyCode){
case Keyboard.UP:
_yDirection = -PIXEL_DISTANCE_TO_DRAW;
break;
case Keyboard.DOWN:
_yDirection = PIXEL_DISTANCE_TO_DRAW;
break;
case Keyboard.LEFT:
_xDirection = -PIXEL_DISTANCE_TO_DRAW;
break;
case Keyboard.RIGHT:
_xDirection = PIXEL_DISTANCE_TO_DRAW;
break;
case Keyboard.SPACE:
_isDrawing = true;
break;
}
}
private function onCanvasKeyUp(event:KeyboardEvent):void{
switch(event.keyCode){
case Keyboard.UP:
case Keyboard.DOWN:
_yDirection = 0;
break;
case Keyboard.LEFT:
case Keyboard.RIGHT:
_xDirection = 0;
break;
case Keyboard.SPACE:
_isDrawing = false;
break;
}
}
private function onCanvasEnterFrame(event:Event):void{
_crosshair.x += _xDirection;
_crosshair.y += _yDirection;
if (_isDrawing){
_canvas.graphics.lineTo(_crosshair.x, _crosshair.y);
}else{
_canvas.graphics.moveTo(_crosshair.x, _crosshair.y);
}
}
}
}
It's an issue with the keyboard and certain combinations of keys.
If you change the keys to WASD like so it works fine:
private function onCanvasKeyDown(event:KeyboardEvent):void{
switch(event.keyCode){
case Keyboard.W:
_yDirection = -PIXEL_DISTANCE_TO_DRAW;
break;
case Keyboard.S:
_yDirection = PIXEL_DISTANCE_TO_DRAW;
break;
case Keyboard.A:
_xDirection = -PIXEL_DISTANCE_TO_DRAW;
break;
case Keyboard.D:
_xDirection = PIXEL_DISTANCE_TO_DRAW;
break;
case Keyboard.SPACE:
_isDrawing = true;
break;
}
}
private function onCanvasKeyUp(event:KeyboardEvent):void{
switch(event.keyCode){
case Keyboard.W:
case Keyboard.S:
_yDirection = 0;
break;
case Keyboard.A:
case Keyboard.D:
_xDirection = 0;
break;
case Keyboard.SPACE:
_isDrawing = false;
break;
}
}
Basically it's due to flawed keyboard design that simplifies the wiring at the expense of some key combinations.
I found this article that explains it in full: http://www.microsoft.com/appliedsciences/antighostingexplained.mspx

Global Variables and GlowFilters is not working

Good day all,
I m new to actionscript3 , and I cant solve few problems on my code. The first problem is glowfilter is not run. According to my research glowfilter 's alpha is set like that but , when ı click true answer it do not response. But the ı try algorithm ıt enter the right case. The second problem is I want to define write answer as global but when ı changed the rightAnswer in a function it is not change,how can ı over this problem ? I think defining global variable in actionscript is different from c .
Thank you for your help and sorry for my bad english!
<s:Button id="answer1" width="388" height="68" label="" cornerRadius="16"
fontFamily="Georgia" fontSize="17" click="checkanswers(1)">
<s:filters>
<mx:GlowFilter id="answer1_glow" color="0x00ff00" alpha="0" strength="3"/>
<mx:GlowFilter id="answer1_glow2" color="0xff0000" alpha="0" strength="3"/>
</s:filters>
</s:Button>
<s:Button id="answer2" width="388" height="68" label="" cornerRadius="16"
fontFamily="Georgia" fontSize="17" click="checkanswers(2)">
<s:filters>
<mx:GlowFilter id="answer2_glow" color="0x00ff00" alpha="0" strength="3"/>
<mx:GlowFilter id="answer2_glow2" color="0xff0000" alpha="0" strength="3"/>
</s:filters>
</s:Button>
<s:Button id="answer3" width="388" height="68" label="" cornerRadius="16"
fontFamily="Georgia" fontSize="17" click="checkanswers(3)">
<s:filters>
<mx:GlowFilter id="answer3_glow" color="0x00ff00" alpha="0" strength="3"/>
<mx:GlowFilter id="answer3_glow2" color="0xff0000" alpha="0" strength="3"/>
</s:filters>
</s:Button>
<s:Button id="answer4" width="388" height="68" label="" cornerRadius="16"
fontFamily="Georgia" fontSize="17" click="checkanswers(4)">
<s:filters>
<mx:GlowFilter id="answer4_glow" color="0x00ff00" alpha="0" strength="3"/>
<mx:GlowFilter id="answer4_glow2" color="0xff0000" alpha="0" strength="3"/>
</s:filters>
</s:Button>
</s:VGroup>
<fx:Script>
<![CDATA[
import flash.events.TimerEvent;
import flash.utils.Timer;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
private var baseTimer:int;
private var t:Timer;
private const TIMER_INTERVAL:Number = 10;
public var rightAnswer:int = 0 ; // ---> ı want to use a global rightAnswer .
public function checkanswers(answer:int):void{
trace("answer is " + answer );
trace("rightanswer is " + rightAnswer);
if ( answer == rightAnswer) {
switch (answer) {
case 1 :
answer1.label = "green";
answer1.alpha = 1; // ı want to change glowfilters alpha in there.
break;
case 2 :
answer2.label = "green";
answer2_glow.alpha = 1;
break;
case 3 :
answer3.label = "green";
answer3_glow.alpha = 1;
break;
case 4 :
answer4.label = "green";
answer4_glow.alpha = 1;
break;
default :
break;
}
}
else{
switch (answer) {
case 1 :
answer1.label = "red";
answer1_glow2.alpha = 1;
break;
case 2 :
answer2.label = "red";
answer2_glow2.alpha = 1.0;
break;
case 3 :
answer3.label = "red;
answer3_glow2.alpha = 1.0;
break;
case 4 :
answer4.label = "red";
answer4_glow2.alpha = 1.0;
break;
default :
break;
}
switch (rightAnswer) {
case 1 :
answer1.label = "green";
answer1_glow.alpha = 1;
break;
case 2 :
answer2.label = "green";
answer2_glow.alpha = 1;
break;
case 3 :
answer3.label = "green";
answer3_glow.alpha = 1;
break;
case 4 :
answer4.label = "green";
answer4_glow.alpha = 1;
break;
default :
break;
}
}
}
public function application1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
soru.text = " En büyük kim ?";
answer1.label = "Galasaray";
answer2.label = "Bursaspor";
answer3.label = "Beşiktaş";
answer4.label = "Fenerbahçe";
var rightAnswer:int = 2;
trace(" rightAnswer fonkideki " + rightAnswer);
}
]]>
</fx:Script>
You issue is with variable scope, it is not doing what you think it is doing.
When you use keyword "var" you re creating a new variable in the current scope.
In this case you are trying to assign 2 to the class level variable "rightAnswer" when in fact you are creating a new variable called "rightAnswer" scoped to function level.
public function application1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
soru.text = " En büyük kim ?";
answer1.label = "Galasaray";
answer2.label = "Bursaspor";
answer3.label = "Beşiktaş";
answer4.label = "Fenerbahçe";
var rightAnswer:int = 2; // <<<<--- right here is your problem
trace(" rightAnswer fonkideki " + rightAnswer);
}
So instead do this.
public function application1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
soru.text = " En büyük kim ?";
answer1.label = "Galasaray";
answer2.label = "Bursaspor";
answer3.label = "Beşiktaş";
answer4.label = "Fenerbahçe";
var rightAnswer:int = 12345678; // <<<<--- right here is your problem
this.rightAnswer = 2; // <<<<--- here is your correction
trace(" rightAnswer class level" + this.rightAnswer);
trace(" rightAnswer function level" + rightAnswer);// << -- this can only be accessed inside of the current function
}

Flex 4.6 Control timer in itemRenderer of TIleList

I am working with Flex 4.6 AIR application. I have a tile list and there is an image as an itemRenderer. When i search images, the data is not filtered but is selected the indices(selected items) of the tilelist and i set a custom property in arrayCollection(dataProvider) then updateDisplayList called and i start a timer in this function. Which perform play the inner images in the selected item.
Now the problem is when if i search the item and click the non selected item the timer is not stoped. How can i achieve that.
The code of itemRenderer is below
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true" buttonMode="true"
click="itemrenderer2_clickHandler(event)"
doubleClick="itemrenderer1_doubleClickHandler(event)" doubleClickEnabled="true"
rightClick="itemrenderer1_rightClickHandler(event)"
rollOut="itemrenderer1_rollOutHandler(event)"
rollOver="itemrenderer1_rollOverHandler(event)" useHandCursor="true">
<fx:Script>
<![CDATA[
import customs.customcomponents.LibraryReDownloadComponent;
import customs.customcomponents.VideoUploadBox;
import dbconnection.Connection;
import globalData.DataModel;
import mx.collections.ArrayCollection;
import mx.core.FlexGlobals;
import mx.core.UIComponent;
import mx.events.ItemClickEvent;
import mx.managers.PopUpManager;
import mx.utils.ObjectProxy;
import mx.utils.UIDUtil;
private var isLoaded:Boolean = false;
private var timer:Timer;
private var rollOverFlag:Boolean = false;
private var countThumb:int = 0;
private var arrThumnail:ArrayCollection;
private var loaderThumb:Loader;
private var request:URLRequest;
private var requestThumb:URLRequest;
private var loader:Loader;
private var sqlStatStatus:SQLStatement;
private var downloadVideoPath:String = "";
private var videoUrlStream:URLStream;
private var videoFileStream:FileStream;
private var uploadvidbox:VideoUploadBox = new VideoUploadBox();
private var dtStartVideo:Date;
private var videoFileName:String = "";
private var videoFile:File;
private var IsRollOver:Boolean = false;
[Bindable]
private var modellocator:DataModel=DataModel.getInstance();
private var connection:Connection = Connection.getInstance();
override public function set data(value:Object):void
{
if(value != null)
{
super.data = value;
if(timer != null)
{
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, showFrame);
timer = null;
}
loaderThumb = new Loader();
rollOverFlag = false;
countThumb = 0;
if(flash.system.Capabilities.os.indexOf("Mac") > -1)
{
requestThumb = new URLRequest("file://" + data.Videothumbnail);
}
else
{
requestThumb = new URLRequest(data.Videothumbnail);
}
loaderThumb.contentLoaderInfo.addEventListener(Event.COMPLETE,onThumbComplete);
loaderThumb.load(requestThumb);
if(data.VideoBuyFlag == "yes")
{
if(data.VideoIsDeleted == "No")
{
bContain.setStyle("borderColor", "#00FF18");
bContain.alpha = 1;
}
else
{
bContain.setStyle("borderColor", "#888888");
bContain.alpha = 0.3;
}
}
else
{
if(data.VideoIsDeleted == "No")
{
bContain.setStyle("borderColor", "#C50000");
bContain.alpha = 1;
}
else
{
bContain.setStyle("borderColor", "#888888");
bContain.alpha = 0.3;
}
}
if(data.VideoStatus == "Active")
{
imgActive.source = "assets/btn_Active.jpg";
bContain.alpha = 1;
}
else
{
imgActive.source = "assets/btn_InActive.jpg";
bContain.alpha = 0.3;
}
arrThumnail = new ArrayCollection();
if(data.Videothumbdata.thumbimage != null)
{
if(data.Videothumbdata.thumbimage.source.item.length > 1)
{
for(var i:int = 0; i < data.Videothumbdata.thumbimage.source.item.length; i++)
{
arrThumnail.addItem(data.Videothumbdata.thumbimage.source.item[i]);
}
}
else
{
arrThumnail.addItem(data.Videothumbdata.thumbimage.source.item);
}
}
}
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
/* trace(data.Videoname);
trace("IsRollOver : " + IsRollOver.toString());
trace("IsSearching : " + data.IsSearching.toString());
trace("rollOverFlag : " + rollOverFlag.toString()); */
if(data.IsSearching == false)
{
if(IsRollOver == false)
{
if(timer != null)
{
trace("inner");
loaderThumb = new Loader();
rollOverFlag = false;
if(flash.system.Capabilities.os.indexOf("Mac") > -1)
{
requestThumb = new URLRequest("file://" + data.Videothumbnail);
}
else
{
requestThumb = new URLRequest(data.Videothumbnail);
}
loaderThumb.contentLoaderInfo.addEventListener(Event.COMPLETE,onThumbComplete);
loaderThumb.load(requestThumb);
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, showFrame);
countThumb= 0;
System.gc();
System.gc();
}
}
}
else
{
if(rollOverFlag == false)
{
rollOverFlag = true;
trace("Hi");
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, showFrame);
timer.start();
}
else
{
if(timer != null)
{
trace("SecondInner");
loaderThumb = new Loader();
rollOverFlag = false;
if(flash.system.Capabilities.os.indexOf("Mac") > -1)
{
requestThumb = new URLRequest("file://" + data.Videothumbnail);
}
else
{
requestThumb = new URLRequest(data.Videothumbnail);
}
loaderThumb.contentLoaderInfo.addEventListener(Event.COMPLETE,onThumbComplete);
loaderThumb.load(requestThumb);
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, showFrame);
countThumb= 0;
System.gc();
System.gc();
}
}
}
}
protected function showFrame(event:TimerEvent):void
{
var file:File;
trace("hello");
if(countThumb < arrThumnail.length)
{
if(flash.system.Capabilities.os.indexOf("Mac") > -1)
{
file = new File("file://" + arrThumnail[countThumb]);
}
else
{
file = new File(arrThumnail[countThumb]);
}
if(file.exists)
{
loader = new Loader();
if(flash.system.Capabilities.os.indexOf("Mac") > -1)
{
request=new URLRequest("file://" + arrThumnail[countThumb]);
}
else
{
request=new URLRequest(arrThumnail[countThumb]);
}
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
loader.load(request);
if(countThumb == (arrThumnail.length - 1))
{
countThumb = 0;
}
else
{
countThumb++;
}
}
else
{
countThumb++;
}
}
else
{
countThumb = 0;
}
}
protected function itemrenderer1_rollOverHandler(event:MouseEvent):void
{
if(data.IsSearching == false)
{
rollOverFlag = true;
IsRollOver = true;
if(arrThumnail != null && arrThumnail.length > 0)
{
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, showFrame);
timer.start();
}
}
}
private function onComplete(event:Event):void
{
if(rollOverFlag)
{
imgThumb.source = loader;
}
}
private function onThumbComplete(event:Event):void
{
imgThumb.source = loaderThumb;
}
protected function itemrenderer1_rollOutHandler(event:MouseEvent):void
{
if(data.IsSearching == false)
{
rollOverFlag = false;
IsRollOver = false;
imgThumb.source = loaderThumb;
if(timer != null)
{
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, showFrame);
timer = null;
}
countThumb = 0;
System.gc();
System.gc();
}
}
protected function itemrenderer2_clickHandler(event:MouseEvent):void
{
for(var i:int=0; i < modellocator.libraryvideoac.length; i++)
{
modellocator.libraryvideoac[i].IsSearching = false;
}
parentDocument.parentDocument.txt_search.text = resourceManager.getString('languages','lblSearchText');
parentDocument.parentDocument.unCheckSelection();
if(data.VideoIsDeleted == "Yes")
{
var popupReDownload:LibraryReDownloadComponent = new LibraryReDownloadComponent();
popupReDownload = PopUpManager.createPopUp(UIComponent(this.parentApplication), LibraryReDownloadComponent, true) as LibraryReDownloadComponent;
popupReDownload.addEventListener("downloadMovie", redownloadMovie);
PopUpManager.centerPopUp(popupReDownload);
}
}
]]>
</fx:Script>
<fx:Declarations>
<mx:NumberFormatter id="numFormat" precision="2"/>
</fx:Declarations>
<s:BorderContainer id="bContain" left="2" top="2" width="92" height="67" backgroundAlpha="1"
backgroundColor="#000000" borderColor="#030304" borderWeight="3">
<s:Image id="imgThumb" width="86" height="61" fillMode="scale" scaleMode="stretch"/>
<s:Image id="imgActive" right="0" bottom="0" width="15" height="15" buttonMode="true"
useHandCursor="true"/>
</s:BorderContainer>
</s:ItemRenderer>
You have timer instantiation at different places in the code. I can't be sure of the actual program flow, but maybe you instantiate the timer two times? In that case program would overwrite the timer variable, and lose reference to the first timer. So, when you call timer.stop() you actually only stop one timer, while the other keeps running in the background.
You didn't set weak reference attribute here:
timer.addEventListener(TimerEvent.TIMER, showFrame);
so the timer will not be garbage collected if you lose its reference (even if you call System.gc() twice :-)). Check that situation out, and try adding a listener with:
timer.addEventListener(TimerEvent.TIMER, showFrame, false, 0, true);