Tuesday, 3 March 2015

CURRENT FRAME AS2 AS3

CURRENT FRAME AS2 AS3

-----------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------




// array for the cards
var cards:Array;
// array for the card pairs
var founds:Array;
// array for the opened cards
var opens:Array;
// frame counter 
var counter:Number;
// delay variable for waiting 
// frames before close cards
var delay:Number;

function init():Void
{
// put cards in cards array
cards = [A, AA, B, BB, C, CC, D, DD, E, EE];
// define empty array
founds = []; opens = [];
// set counter value and delay value
counter = 0; delay = 24;
// loop through cards
for(var i:Number = 0; i < cards.length; i++)
{
// take single card fro the cards array
var card:MovieClip = cards[i];
// set onPress listener for the card
card.onPress = onPressEvent;
// set card not to be open
card.open = false;
}
}

function checkOpens(current:MovieClip):Boolean
{
// loop through cards array
for(var i:Number = 0; i < cards.length; i++)
{
// take single card out from the cards array
var card:MovieClip = cards[i];
// check if the frame of the card is 17
if(card._currentframe == 17)
{
// check if current card and the card
// that isn't the current card have same 
// first letter in the name
if(current != card && current._name.charAt(0) == card._name.charAt(0))
{
// return true
return true;
}
}
}
// return false if the correct pair of the 
// cards couldn't found
return false;
}

function setDelay():Void
{
// start wait enterframe
this.onEnterFrame = wait;
}

function wait():Void
{
// check if counter is more or same than number 
// of the delay
if(counter++ >= delay)
{
// close cards
closeCards();
// reset counter
counter = 0;
// delete wait enterframe
delete this.onEnterFrame;
}
}

function closeCards():Void
{
// loop through the cards
for(var i:Number = 0; i < cards.length; i++)
{
// take single card from the cards array
var card:MovieClip = cards[i];
// check if the frame number of the card
// is 17
if(card._currentframe == 17)
{
// turn card
card.onEnterFrame = turnCard;
}
}
}

function pairFound():Void
{
trace("show this message");
// loop through cards
for(var i:Number = 0; i < cards.length; i++)
{
// take single card from array
var card:MovieClip = cards[i];
// check if card is in frame 17
if(card._currentframe == 17)
{
// delete onPress listener fom the card
delete card.onPress;
// cut card from the cards array to the
// founds array
founds.push(cards.splice(i, 1));
// clear opens array for the nex two cards
opens = [];
// step one index backward
i--;
}
}
}

/* function operates inside of the 
 * card movieClip. That's why there 
 * need to be used "this" and the "_root"
 * prepositions
 */
function onPressEvent():Void
{
// check if there are non or one card open
if(_root.opens.length < 2)
{
// pushes card in the open array
_root.opens.push(this);
// check if the frame is one
if(this._currentframe == 1)
{
// enable card to open
this.open = true;
// set listener function for enterframe
// to turn the card open
this.onEnterFrame = turnCard;
// checks if correct cards are open
_root.checkOpens(this);
}
}
}

/* function operates inside of the 
 * card movieClip. That's why there 
 * need to be used "this" and the "_root"
 * prepositions
 */
function turnCard():Void
{
// check if card can be turned to open
if(this.open)
{
// check if the current frame of the card
// is less than 17
if(this._currentframe < 17)
{
// go one frame forward
this.gotoAndStop(this._currentframe + 1);
// check if the current frame is 17
if(this._currentframe == 17)
{
// set card to be able to turned to close
this.open = false;
// check if two cards are open
if(_root.opens.length == 2)
{
// checks if cards are not a pair and if so
// set delay before close cards or if not
// remove cards from cards array and disable
// the press function call
!checkOpens(this) ? _root.setDelay() : _root.pairFound();
}
// remove the enterframe listener
delete this.onEnterFrame;
}
}
}
else
{
// check if frame isn't not 1
if(this._currentframe != 1)
{
// step back one frame
this.gotoAndStop(this._currentframe - 1);
// check if the frame is one
if(this._currentframe == 1)
{
// enable the card to be open
this.open = true;
// clear opens array for the next two
// cards
_root.opens = [];
// remove the enterframe listener
delete this.onEnterFrame;
}
}
}
}

init();


Below are examples of these new Timeline properties.Return the current label within a MovieClip

AS3 Code: Current Label

Return a list of all the labels within a MovieClip

AS Code Currentlabels

Return a frame label’s frame number and name

</p>

Check how many labels are within a MovieClip

AS3 Code Current Length

Determine what the last frame label of a specific MovieClip is

AS3 Code Array Pop

Check the frame number of where a frame label resides

AS3 Get Frame Number
------------------------------------------------------------------------------------------------------------------------
OTHER EXAMPLES
http://gotoanswer.stanford.edu/?q=Play+in+reverse
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7d9d.html
-----------------------------------------------------------------------------------------------------------------------
onClipEvent (enterFrame) {
    if (_root.playBackwards == true) {
        this.gotoAndStop(this._currentframe-1);
        if(this._currentframe == 1) {
            this.gotoAndStop(this._totalframes)
        }
    } else {
        this.gotoAndPlay(this._currentframe+1);
    }
}
---------------------------------------------------------------------------------------------------------------------------
function playControl(mc, speed, targetframe) {
speed == undefined ? speed=20 : null;
mc.targetframe = targetframe == undefined ? mc._totalframes : targetframe;

if (mc.targetframe > mc._totalframes) mc.targetframe = mc._totalframes
else if (mc.targetframe < 1) mc.targetframe = 1

if(!mc.isPlaying){
mc.isPlaying = setInterval(
function(){
if (mc._currentframe > mc.targetframe) {
 mc.prevFrame();

else if (mc._currentframe < mc.targetframe) {
 mc.nextFrame();
}
else {
 clearInterval(mc.isPlaying); 
 delete mc.isPlaying;
}
} ,speed)
}
}

function setPlayControl(mc){
mc.stop();
}
-------------------------------------------------------------------------------------------------------------------------
https://forums.creativecow.net/thread/190/869829
-------------------------------------------------------------------------------------------------------------------------
mc1.stop();
mc2.stop();
b1.addEventListener(MouseEvent.CLICK, playMC1);
function playMC1(e:MouseEvent):void {
mc2.stop();
mc1.gotoAndPlay(mc2.currentFrame);
}
b2.addEventListener(MouseEvent.CLICK, playMC2);
function playMC2(e:MouseEvent):void {
mc1.stop();
mc2.gotoAndPlay(mc1.currentFrame);
}
------------------------------------------------------------------------------------------------------------------

mtlyrvult.stop();
itlyrvult.stop();

engvult.addEventListener(MouseEvent.CLICK, playMC1); 
function playMC1(e:MouseEvent):void {
    itlyrvult.stop();
    enlyrvult.gotoAndPlay(itlyrvult.currentFrame);
    itlyrvult.gotoAndStop(1);  //frame one is empty
    engvult.mouseEnabled = false;
    itvult.mouseEnabled = true;
}

itvult.addEventListener(MouseEvent.CLICK, playMC2);
 function playMC2(e:MouseEvent):void {
    enlyrvult.stop();
    itlyrvult.gotoAndPlay(enlyrvult.currentFrame);
    enlyrvult.gotoAndStop(1);    //frame one is empty
    itvult.mouseEnabled = false;
    engvult.mouseEnabled = true;

}
-------------------------------------------------------------------------------------------------------------
INSIDE  MOVIE CLIP PROPERTIES CLASS NAME = Hero
----------------------------------------------------------------------------------------------------------------
var hero:Hero = new Hero();
hero.x = 100;
hero.y = 200;
addChild(hero);
hero.addEventListener(MouseEvent.CLICK, hideMe);
function hideMe(e:MouseEvent):void{
if (hero.currentFrame == 1) {
hero.gotoAndStop(hero.currentFrame+1);

}





EmoticonEmoticon