A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: onPress

  1. #1
    Senior Member
    Join Date
    Aug 2012
    Posts
    115

    onPress

    Hello,

    I seem to be stuck with making the buttons work when ive created and attached them.

    They work but not how i want them to.

    They all trace the same output when infact i want them to trace each part of the array separately.

    Actionscript Code:
    NewImages = new Array("backgrounds/1.jpg", "backgrounds/2.jpg", "backgrounds/3.jpg", "backgrounds/4.jpg", "backgrounds/5.jpg");
    HowMany = NewImages.length;

    ImageMenu.createEmptyMovieClip("NewImageMenu",1);
    ImageMenu["NewImageMenu"]._x = 0;
    ImageMenu["NewImageMenu"]._y = 0;
    ImageMenu["NewImageMenu"].setMask(ImageMenu.AttachedMasker);

    function Creation()
    {
        for (j = 0; j < HowMany; j++)
        {
            ImageMenu.NewImageMenu.attachMovie("Imager","NewImageButton" + j,j,true);
            ImageMenu.NewImageMenu["NewImageButton" + j]._x = (j + 2) * (ImageMenu.NewImageMenu["NewImageButton" + j]._width + 3);
            ImageMenu.NewImageMenu["NewImageButton" + j]._y = j % 1;
            ImageMenu.NewImageMenu["NewImageButton" + j].filters = [Drop1];
            ImageMenu.NewImageMenu["NewImageButton" + j].onRelease = function()
            {
                trace(j + ". " + NewImages[i]);
                trace("Pressed");
            };
            ImageMenu.NewImageMenu["NewImageButton" + j].onRollOver = function()
            {
                this.useHandCursor = false;
            };
            ImageMenu.NewImageMenu["NewImageButton" + j].onRollOut = function()
            {//empty
            };
        }
    }

    Creation();

    they all trace 5. backgrounds/1.jpg
    Pressed when i want

    1. backgrounds/1.jpg
    Pressed

    2. backgrounds/2.jpg
    Pressed

  2. #2
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    276
    Your trace function should use "j" instead of "i", not sure if "i" is set somewhere else.

    Code:
     trace(j + ". " + NewImages[j]);

  3. #3
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    Hi,

    Thanks for looking, that does not not help me though.

    It was just a typo too.

    Cheers

  4. #4
    Senior Member Steven FN's Avatar
    Join Date
    Mar 2010
    Location
    CA, USA
    Posts
    276
    Ok, didn't know it was a typo. Try this. I remember back when i used AS2 that i had problems like this. Solution was to add a variable to hold the instance number.

    Code:
    ImageMenu.NewImageMenu["NewImageButton" + j].num = j;
    ImageMenu.NewImageMenu["NewImageButton" + j].onRelease = function()
    {
       trace(this.num);
       trace("Pressed");
    };

  5. #5
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    Thank you Sir,

    You are the rodriguez of desire

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center