Skip to main content
DMB89
Known Participant
November 22, 2013
Answered

movieclips, buttons and arrays - oh the joys

  • November 22, 2013
  • 1 reply
  • 573 views

I am having such an issue working with arrays, im not great at fpash but decided to try a different approach to writing out the same functions for different buttons over and over again.

The plan is meant to be:

6 movieclip buttons on stage (markers) and 6 movieclip boxes on stage (panels). click a marker and it plays the fade in animation within the panel.

access/call the close button.onRelease function; location within the animated movieclip of the original panel movieclip (p1.p1_an.close_btn) to then call rewindframes(); to fade out the panel back to square one again.

repeat for all 6 buttons and clips.

Here is my code. i know its probably got something to do with strings and converting values to objects etc but i have tried so many things i just cannot get it to work.

please help

stop();

var myMarker = new Array (marker1, marker2, marker3, marker4, marker5, marker6);

var myPanel = new Array(p1, p2, p3, p4, p5, p6);

//***************************//

// Markers buttons

//***************************//

for (var i = 1; i < myMarker.length; i++)

{

    myMarker.onRelease = function()

    {

        play();//fadeout markers

       

        playPanel(myPanel); // play panel 1 to 6 depending on marker clicked   

       

        this[myPanel + "." myPanel + "_an"].close_btn.onRelease = function() //location of close button example - p1.p1_an.close_btn

        {

            rewindFrames(myPanel); // function to rewind frames of panel fade in animation back to frame 0;

        };

    };

}

//***************************//

// Play Panel

//***************************//

function playPanel(panelName)

{

    panelName.play();

}

//***************************//

// Rewind Panel

//***************************//

function rewindFrames(panelName)

{

    panelName.onEnterFrame = function()

    {

        if (panelName._currentframe != 1)

        {

            panelName.prevFrame();

        }

        else

        {

            panelName.stop();

            delete this["onEnterFrame"];

        }

    };

}

//***************************//

// Fade in Markers

//***************************//

function fadeInMarkers()

{

    onEnterFrame = function ()

    {

        if (_currentframe != 30)

        {

            prevFrame();

        }

        else

        {

            stop();

            delete this["onEnterFrame"];

        }

    };

}

This topic has been closed for replies.
Correct answer kglad

use:

stop();

var myMarker = new Array (marker1, marker2, marker3, marker4, marker5, marker6);
var myPanel = new Array(p1, p2, p3, p4, p5, p6);

//***************************//
// Markers buttons
//***************************//

for (var i = 1; i < myMarker.length; i++)
{
myMarker.ivar=i;
     myMarker.onRelease = function()     {         play();//fadeout markers                 playPanel(myPanel[this.ivar]); // play panel 1 to 6 depending on marker clicked   
// the line below looks screwy. but if there really is a p1.p1, p2.p2 etc this is one way to encode it

myPanel[this.ivar][myPanel[this.ivar]._name].close_btn
.onRelease = function() //location of close button example - p1.p1_an.close_btn         {             rewindFrames(this._parent._parent); // function to rewind frames of panel fade in animation back to frame 0;         };     }; }

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 22, 2013

use:

stop();

var myMarker = new Array (marker1, marker2, marker3, marker4, marker5, marker6);
var myPanel = new Array(p1, p2, p3, p4, p5, p6);

//***************************//
// Markers buttons
//***************************//

for (var i = 1; i < myMarker.length; i++)
{
myMarker.ivar=i;
     myMarker.onRelease = function()     {         play();//fadeout markers                 playPanel(myPanel[this.ivar]); // play panel 1 to 6 depending on marker clicked   
// the line below looks screwy. but if there really is a p1.p1, p2.p2 etc this is one way to encode it

myPanel[this.ivar][myPanel[this.ivar]._name].close_btn
.onRelease = function() //location of close button example - p1.p1_an.close_btn         {             rewindFrames(this._parent._parent); // function to rewind frames of panel fade in animation back to frame 0;         };     }; }
DMB89
DMB89Author
Known Participant
November 22, 2013

thankyou very much, this has good me alot further already. the line below is meant to convert to the following depending on the marker clicked. you are right it doent work but everything else did:

p1.p1_an.close_btn.onRelease = function()

p2.p2_an.close_btn.onRelease = function()

p3.p3_an.close_btn.onRelease = function()

p4.p4_an.close_btn.onRelease = function()

p5.p5_an.close_btn.onRelease = function()

p6.p6_an.close_btn.onRelease = function()

// the line below looks screwy.  i'm not sure what it's supposed to do but it's not likely to work.       
        this[myPanel[this.ivar] + "." myPanel[this.ivar] + "_an"].close_btn.onRelease = function() //location of close button example - p1.p1_an.close_btn

kglad
Community Expert
Community Expert
November 22, 2013

check my updated message.  i think i figured out what you're trying to do.