A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] [FLASH 8 AS2]Messed up functions

  1. #1
    Junior Member
    Join Date
    Feb 2016
    Posts
    5

    resolved [RESOLVED] [FLASH 8 AS2]Messed up functions

    So, I am making this game where the player can place "boxes" of sorts, and then click on a "material", the cursor would change, then click on the box and it will switch to another frame. And so consecutively until you get and end result

    However, after a while working with it, the first "box" (which is used for building a capfire in the game) wouldn't place down. The cursor did not even switch to its alternative shape.

    The sole variable used (_root.inUse) works ecelently, and another "box" too. I checked everything, but I can't find why the campfire won't work.

    I can't really find what is wrong with my script, and since the game relies heavily on that mechanic, I'm afraid I can't do much if I leave the problem like that. I ask for your help. Please.
    I leave the script and the .fla itself for revision.

    Cursor(relies mainly on the cursor's function):


    onClipEvent (enterFrame) {
    //Setting up the cursor
    Mouse.hide();
    this._x = _root._xmouse;
    this._y = _root._ymouse;
    //Using the tile-based cursor when a campfire building space is selected
    if (_root.inUse == -1) {
    this.gotoAndStop(2);
    } else {
    this.gotoAndStop(1);
    }
    //Placing the space for making the campfire
    onMouseDown = function () {
    if (_root.inUse == -1) {
    if (this.hitTest(_root.ground)) {
    _root.attachMovie("campfire_build", "campfire", _root.getNextHighestDepth(), {_xthis._x), _ythis._y)});
    _root.inUse = 0;
    }
    _root.getNextHighestDepth();
    }
    };
    //Using the tile-based cursor when a tent building space is selected
    if (_root.inUse == -2) {
    this.gotoAndStop(2);
    } else {
    this.gotoAndStop(1);
    }
    //Placing the space for making the tent
    onMouseDown = function () {
    if (_root.inUse == -2) {
    if (this.hitTest(_root.ground)) {
    _root.attachMovie("tent_build", "tent", _root.getNextHighestDepth(), {_xthis._x), _ythis._y)});
    _root.inUse = 0;
    }
    _root.getNextHighestDepth();
    }
    };
    _root.getNextHighestDepth();
    }




    Would take much more to write down the whole thing. I hope you can find a solution. Thank you again

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,834
    In the future, I suggest you disable smilies in text when posting code.

    I don't understand what you're trying to achieve by using getNextHighestDepth() by itself. That method is for retrieving a number. It doesn't do anything by itself.

    Now, with that out of the way, the problem you're running into is you're replacing the first onMouseDown function with the second one. In other words, the code you have to place the tent replaces the code you have for placing the campfire. i.e.
    a = code to place campfire
    a = code to place tent
    campfire's code is lost.

    A lot of your problem in this case is you're spreading your code all over the place. So, instead of having each box have an onEnterFrame function, try only having one that controls everything. Also, you don't want to keep running code that you don't need to. I'll show you what I mean with the code fix I'm posting.

    Code:
    onClipEvent (enterFrame) {
    	this._x = _root._xmouse;
    	this._y = _root._ymouse;
    	//Using the tile-based cursor when a campfire building space is selected
    	if (_root.inUse == -1 || _root.inUse == -2) {
    		this.gotoAndStop(2);
    	} else {
    		this.gotoAndStop(1);
    	}
    }
    onClipEvent (load) {
    	//Setting up the cursor
    	Mouse.hide();
    	//Placing the space for making the campfire and tent
    	onMouseDown = function () {
    		if (this.hitTest(_root.ground)) {
    			switch (_root.inUse) {
    				case -1 :
    					_root.attachMovie("campfire_build","campfire",_root.getNextHighestDepth(),{_x:(this._x), _y:(this._y)});
    					break;
    				case -2 :
    					_root.attachMovie("tent_build","tent",_root.getNextHighestDepth(),{_x:(this._x), _y:(this._y)});
    					break;
    			}
    			_root.inUse = 0;
    		}
    	};
    }
    I like to reduce the amount of code needed, it's a lot cleaner.
    .

  3. #3
    Junior Member
    Join Date
    Feb 2016
    Posts
    5
    I didn't mean to place the emojis there. Should've put some spaces between those. The GetNextHighestDepth was a small experiment.

    That left alone, thank you for the help! I didn't know that multiple activators cancelled each other. I want to thank you again!

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