4 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
Fr0ztz says

Hi guys

basically im working on a flash game at the moment and in the “coin” class file i need to drag the coin in question around the stage and have it scale up or down based on its Y position (to give a sense of a 3d environment)

the problem im encountering is that once the coin scales down below 0 it returns that its not a number and bugs out. causing my stage to turn brown and the scaling stops as well so it doesnt return to its normal size.

let me link you the code in question

package
{
    import         caurina.transitions.Tweener;
    import         caurina.transitions.properties.FilterShortcuts;
    import        fl.transitions.Tween;
    import        fl.transitions.easing.None;
    import      flash.display.MovieClip;
    import         flash.events.MouseEvent;
    import        flash.events.Event;
    import        flash.media.Sound;
    import        flash.media.SoundChannel;
    import        flash.media.SoundTransform;
    import        flash.net.URLRequest;
    import         flash.filters.*;

    public class Coin extends MovieClip
    {
        public function Coin():void
        {
            trace("*** MINICODE ALERT *** Coin Class Loaded");

            this.addEventListener(MouseEvent.MOUSE_DOWN, drag);
            this.addEventListener(MouseEvent.MOUSE_UP, drop);
            this.addEventListener(MouseEvent.MOUSE_MOVE, onMove);

            FilterShortcuts.init();
        }

        private var dragging:Boolean = false;
        private var coinDropUrl:URLRequest = new URLRequest("Sounds/coinDrop.mp3");
        private var coinDrop:Sound    = new Sound();
        private var coinRegisteredUrl:URLRequest = new URLRequest("Sounds/coinRegistered.mp3");
        private var coinRegistered:Sound = new Sound();
        private var scaleTweenX:Tween;
        private var scaleTweenY:Tween;

        private function drag(e:MouseEvent):void
        {
            e.currentTarget.startDrag(true);
            dragging = true;
        }

        //COIN RELEASED FUNCTIONALITY
        private var externalSentScale:Number;

        private function drop(e:MouseEvent):void
        {
            e.currentTarget.stopDrag();
            dragging = false;
            this.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
            this.dispatchEvent(new Event("coinHitCheck", true));
        }

        public function dropReply(status:String, sentX:int, sentY:int, sentScale:Number):void{
            externalSentScale = sentScale;
            if(status == "offMeter"){
                Tweener.addTween(this,{y:1000, time:1, transition:"easeInSine", onComplete:coinHitFloor});
                trace('Dropping');
            }else if (status == "onMeter"){
                Tweener.addTween(this,{ x:sentX, y:sentY, time:.4, transition:"easeInSine", onComplete:coinInserted});
                scaleTweenX = new Tween(this, "scaleX", None.easeNone, this.scaleX, sentScale, .5, true);
                scaleTweenY = new Tween(this, "scaleY", None.easeNone, this.scaleY, sentScale, .5, true);
                Tweener.addTween(this, {_Blur_blurX:5,_Blur_blurY:0, time:.5});
            }

        }

        private function coinHitFloor():void
        {
            this.dispatchEvent(new Event("destroyMe", true));
            coinDrop.load(coinDropUrl);
            coinDrop.play();
        }

        private function coinInserted():void
        {
            Tweener.addTween(this,{ x:this.x+(externalSentScale*100), time:.2, transition:"easeInSine", onComplete:coinRegisteredFunction});
        }

        private function coinRegisteredFunction():void{
            //this.dispatchEvent(new Event("coinRegistered", true));
            coinRegistered.load(coinRegisteredUrl);
            coinRegistered.play();
            this.alpha = 0;
        }

        private function onMove(e:MouseEvent):void
        {
            if(dragging) {

                    var currScale = Math.sqrt((this.y-200)/1000);
                    var fixScale:Number = currScale.toFixed(2);
                    if(e.currentTarget.scaleX && e.currentTarget.scaleY > 1){
                        e.currentTarget.scaleY = 1;
                        e.currentTarget.scaleX = 1;
                    }else if(e.currentTarget.scaleX && e.currentTarget.scaleY < 0.1){
                        e.currentTarget.scaleY = 0.1;
                        e.currentTarget.scaleX = 0.1;
                    }else{
                        e.currentTarget.scaleX = fixScale;
                        e.currentTarget.scaleY = fixScale;
                    }
                    trace('--------Scale--------');
                    trace(fixScale);
                    trace('---------------------');
                    trace(e.currentTarget.scaleX);
            }
        }
    }
}

ive spent all day bangin my head against a wall on this one. ive messed around with the setSize method and not had any joy, it seems to me that the else if statement where it checks to see if the currentTarget goes below 0.1 just isnt being taken into consideration at all as it just keeps scaling down regardless.

any help would be legendary.

cheers

1955 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Netherlands
  • Referred between 10 and 49 users
  • Sold between 5 000 and 10 000 dollars
Emroni says

Best thing to do (well, at least what I can think of right now..), is have a variable calculate what the next scale will be, rather than scaling the object immediately. Because right now, it scales it down first, and then checks it, but then its already to late.

5311 posts The Dude Abides
  • United States
  • Exclusive Author
  • Has been a member for 5-6 years
  • Elite Author
  • Bought between 100 and 499 items
  • Referred between 100 and 199 users
  • Author had a Free File of the Month
+5 more
CodingJack says

Hey Emri your avatar is awesome :)

133 posts
  • United States
  • Sold between 10 000 and 50 000 dollars
  • Has been a member for 6-7 years
  • Exclusive Author
  • Referred between 1 and 9 users
  • Bought between 10 and 49 items
ZacharyKnight says

Crap, Fr0ztz...you’re scaring the heck out of me!

I’ve decided to make the jump to AS3 , but your code looks like a nightmare! :?

How long ago did you make (start) the transition to AS3 ? And did you have a good grasp of classes before?

4 posts
  • Bought between 100 and 499 items
  • Has been a member for 7-8 years
Fr0ztz says

Hi ZacharyKnight

only been using AS3 for a few months now but the reason this class looks so manic is because its just one aspect of the game, the whole thing is HUGE . This class has to “bubble” values back up to the main app and vice versa to be honest i dont fully understand all of it but then i dont really have to, im one of 3 guys working on this and the project mamager is working on the main app. im mainly focusing on the smaller aspect like this coin class.

I dont have any experience with AS2 but from what people have told me it was alot simpler code wise and allowed you to write less in certain situations but then again it sometimes forced you to over elaborate in others (at least this is my understanding)

If you havent really experienced much AS3 i can totally understand how this might look scary.

anyway thanks for the advice everyone im gonna give it another crack today and may or may not get back to you :D

133 posts
  • United States
  • Sold between 10 000 and 50 000 dollars
  • Has been a member for 6-7 years
  • Exclusive Author
  • Referred between 1 and 9 users
  • Bought between 10 and 49 items
ZacharyKnight says

Thanx for the reply. I’ve heard the same thing…like, getting a URL in AS3 is 3x more complicated but parsing XML is a breeze.

I guess I’ll find out as I’m starting to learn game development in AS3 next week.

Good luck with your code!

5311 posts The Dude Abides
  • United States
  • Exclusive Author
  • Has been a member for 5-6 years
  • Elite Author
  • Bought between 100 and 499 items
  • Referred between 100 and 199 users
  • Author had a Free File of the Month
+5 more
CodingJack says

There’s a lot to examine there but I think in general a good old fashioned enterFrame might do the trick.

You could listen for the scales and then if they equal zero kill the tweens maybe?

4140 posts
  • Bought between 1 and 9 items
  • Brazil
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 1 and 9 users
  • Sold between 5 000 and 10 000 dollars
tsafi says

AS2 is much simpler then AS3 it’s a fact, in a way the command in AS2 is shorter and much easier to understand, but AS3 have grater performance on all parameters.

The class in AS3 can be tricky and the majority work with class, coding on the time-line is much easier then class but working on the timeline is inferior as to organize class and recycle code, most developer working only with class and in a way it’s a deferential approach when working as to time-line coding.

When working with class think of this like you have many pipeline and they all connect to the main tap, once all the water reach the tap he direct the water to there place and synchronize all of them together, not before the conductor(you) tell the tap what to do? easy no ? :p

145 posts
  • Australia
  • Bought between 1 and 9 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 10 and 49 users
  • Sold between 10 000 and 50 000 dollars
bjornredemption says

I’ve just started my first major project using AS3 – before this id done all my work in AS2 and although it may seem annoyingly complicated i think in the long run it’ll be worthwhile. (I hope!!)

The major pain i had to get over was still thinking in AS2 but writing the code in AS3 ! I have a sneaky suspicion that if you’re starting off with no knowledge of AS2 you might find it easier to adapt.

46 posts
  • Author had a Free File of the Month
  • Sold between 5 000 and 10 000 dollars
  • Exclusive Author
  • Has been a member for 5-6 years
  • Author had a File in an Envato Bundle
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
+1 more
golle says
Try:
(e.currentTarget.scaleX < 0.1 && e.currentTarget.scaleY < 0.1)        
by
by
by
by
by
by