Skip to main content
February 13, 2013
Question

hi

  • February 13, 2013
  • 1 reply
  • 1203 views

i  have a problem

on the secound  frame i collect objects  all goes well, i do see the text how many item i have to collect more

on the fourth ihaea nother items, i can collcet them but the text is mising , dont tellme how many items i have to collect more

the objects are link to the invetoryitems on the base class

thisis my invetoryitem class

package

{

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    import flash.media.Sound;

   

   

    public class InventoryItem extends MovieClip

    {

        public function InventoryItem()

        {

            // constructor code

            this.buttonMode = true;

            this.addEventListener(MouseEvent.CLICK, mouseClickHandler);

        }

        private function mouseClickHandler(e:MouseEvent):void

        {

            this.removeEventListener(MouseEvent.CLICK, mouseClickHandler);

            this.buttonMode = false;

            Main.instance.insertToInventory(this);

            var s:Sound = new button4();

            s.play();

            //addBubbles(e.currentTarget);

        }

        /*private function addBubbles(e:Object):void

        {

           

            var xx:Number = e.x;

            var yy:Number = e.y;

            var bubble:ballg = new ballg();

            bubble.x = xx;

            bubble.y = yy;

            e.parent.addChild(bubble);

            bubble.gotoAndPlay(1);

        }*/

    }

}

do i need to add something on my invetoryclass?

Thank you

This topic has been closed for replies.

1 reply

kglad
Adobe Expert
February 14, 2013

there's nothing in that class that displays text.  you must have that code elsewhere.

February 14, 2013

Hi

ok this is my code

it's  working just to frame 1 but doesnt work at frame 4 , and yes i have keyframe at frame 4 as well

at frame 4 i can collect the items like at frame one BUT the text i cant see, i cant find  why is that

thank you for your help

package

{

    import flash.display.MovieClip;

    import flash.display.DisplayObject;

    import com.greensock.TweenMax;

public class Main extends MovieClip

    {

        public static var instance:Main;

        public var totalInventoryItems:Number;

        public var collected:Number;

        public var remaining:Number;

        public var inventory:Array;

        public function Main()

        {

            // constructor code

            Main.instance = this;

            collected = 0;

            txt.text = " ";

            stop();

        }

        public function prepareStage()

        {

            inventory = new Array();

            totalInventoryItems = 0;

            for (var i:int = 0; i < this.numChildren; i++)

            {

                if (this.getChildAt(i) is InventoryItem)

                {

                    totalInventoryItems++;

                }

            }

            trace("totalInventoryItems", totalInventoryItems);

        }

        public function insertToInventory(object:DisplayObject)

        {

            var xx:Number = (68 - object.width)/2;

           

            if (inventory.length > 0)

            {

                TweenMax.to(object, 1, {x:xx, y:inventory[inventory.length - 1].y + inventory[inventory.length - 1].height + 10});

            }

            else

            {

                TweenMax.to(object, 1, {x:xx, y:10});

            }

            inventory.push(object);

            if (inventory.length == totalInventoryItems)

            {

                this.nextFrame();

                prepareStage();

            }

            collected++;

            remaining = totalInventoryItems - collected;

            txt.text = "you still have " + String(remaining) + " objects to collect.";

            if(remaining <= 1)

            {

                txt.text = "You still have " + String(remaining) + " object to collect.";

            }

            if(remaining <= 0)

            {

                txt.text = "";

            }

        }

    }

}

February 14, 2013

Hi

that's what i got at the trace

totalInventoryItems 10

-2 4

-3 4

-4 4

-5 4

-6 4

-7 4

-8 4

-9 4

what that means? still cant see  the message how many item more to collect

Thank you


OK thank you so much

now i see the problem

i use Math.abs and i fix it

Thank you