4 posts
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
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
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+3 more
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.

5406 posts The Dude Abides
  • Located in United States
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
+9 more
CodingJack says

Hey Emri your avatar is awesome :)

133 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
+3 more
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
  • Has been part of the Envato Community for over 7 years
  • Has collected 100+ items on Envato Market
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
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
+3 more
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!

5406 posts The Dude Abides
  • Located in United States
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $125,000+ on Envato Market
  • Has been part of the Envato Community for over 5 years
+9 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
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Located in Brazil
+3 more
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
  • Has been part of the Envato Community for over 6 years
  • Has referred 10+ members
  • Located in Australia
  • Has sold $10,000+ on Envato Market
+2 more
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
  • Has sold $5,000+ on Envato Market
  • Had an item featured on Envato Market
  • Made it to the Authors' Hall of Fame
  • Contributed a free file of the month
+6 more
golle says
Try:
(e.currentTarget.scaleX < 0.1 && e.currentTarget.scaleY < 0.1)        

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by