dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: boolean variable used for cimple flag not working, remains unassigned when traced

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

    boolean variable used for cimple flag not working, remains unassigned when traced

    I am using Flash 8, AS2. I am inexperienced with programming, and realize I may be approaching my goal entirely wrong.

    I am using a movie clip to represent a blip/button, that when hovered over with the mouse, triggers an infobox to appear. On the mouse rollout, I disable the visibility of the infobox, on the condition that a flag is set to false.

    All of my code is within the blip movieclip. The problem I am having, is that I want the infobox to remain visible when the blip is clicked, which sets the flag to true, but my code is reacting as if the flag is undefined or maybe does not exist. For instance, on rollout, the infobox does not disappear as it should when the movieclip remains unclicked.

    I know this has to be a simple problem, though I am a newbie and cannot figure it out. I trace the value of the flag variable and it comes back as undefined. All help is appreciated.

    this is the code within the movieclip, the variable in question is at the top.
    Code:
    onClipEvent (enterFrame) {
    	var flag:Boolean;
    	
    	this.onRollOver = function() {
    		_root.infobox1._visible = true;
    		setProperty(_root.infobox1, _x, getProperty(this, _x));
    		setProperty(_root.infobox1, _y, getProperty(this, _y)-40);
    		this.play();
    		import blipTween;
    		var tween1:blipTween = new blipTween(this);
    		
    		trace(flag.valueOf());
    	};
    	this.onRelease = function() {
    		if (flag=false) {
    			flag = true;
    		}
    	};
    	this.onRollOut = function() {
    		if (flag=false) {
    			_root.infobox1._visible = false;
    			import blipTween;
    			var tween2:blipTween2 = new blipTween2(this);
    			this.gotoAndStop(1);
    		}
    	};
    }
    Am I assigning the var incorrectly at the beginning? Am I referencing the variable incorrectly within the rollover/rollout functions? why does the trace tell me the flag is undefined if boolean variables default to false?

  2. #2
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,029
    var flag:Boolean;

    onClipEvent (enterFrame) {

    this.onRollOver = function() {
    _root.infobox1._visible = true;
    setProperty(_root.infobox1, _x, getProperty(this, _x));
    setProperty(_root.infobox1, _y, getProperty(this, _y)-40);
    this.play();
    import blipTween;
    var tween1:blipTween = new blipTween(this);

    trace(_root.flag.valueOf());
    };

    this.onRelease = function() {
    if (_root.flag=false) {
    _root.flag = true;
    }
    };
    this.onRollOut = function() {
    if (_root.flag=false) {
    _root.infobox1._visible = false;
    import blipTween;
    var tween2:blipTween2 = new blipTween2(this);
    this.gotoAndStop(1);

    };
    }
    }







    try that

  3. #3
    Junior Member
    Join Date
    Dec 2016
    Posts
    5
    Thank you for the response, unfortunately I've tried that avenue already, and got this error:
    Code:
    **Error** Scene=Scene 1, layer=Layer 2, frame=1:Line 1: Statement must appear within on/onClipEvent handler
         	var flag:Boolean;
    
    Total ActionScript Errors: 1 	 Reported Errors: 1
    I put the variable before the onClipEvent handler with the line of thinking was that the variable wasn't getting accessed, with some barrier of locality in the way that was beyond my understanding, however I still ended up with this error.. any other ideas as to what I've gotten myself into? I like to think that using a boolean flag should be simple enough for me to accomplish..

  4. #4
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,029
    try it with the var on the main timeline

  5. #5
    Junior Member
    Join Date
    Dec 2016
    Posts
    5
    Now it was the same as before, no error, but the rollout function isn't responding to the variable at all. and the trace still returns undefined. im having trouble uploading the fla, let me see if i can get it uploaded in the next few minutes

  6. #6
    Junior Member
    Join Date
    Dec 2016
    Posts
    5
    blip.fla

    for some reason i cant upload my custom class file, here it is in code if you want to create it, otherwise comment out the tween parts in the blip1 movieclip

    Code:
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    class blipTween {
    	public function blipTween(_mc:MovieClip) {
    		var easeType = Regular.easeOut;
    		var begin = getProperty(_mc, _xscale);
    		var end = 130;
    		var time = .5;
    		var mc = _mc;
    		var blip1Tween = new Tween(mc, "_xscale", easeType, begin, end, time, true);
    		var blip1Tween2 = new Tween(mc, "_yscale", easeType, begin, end, time, true);
    	}
    	public function blipTween2(_mc:MovieClip) {
    		var easeType = Regular.easeOut;
    		var begin = getProperty(_mc, _xscale);
    		var end = 100;
    		var time = .5;
    		var mc = _mc;
    		var blip1Tween = new Tween(mc, "_xscale", easeType, begin, end, time, true);
    		var blip1Tween2 = new Tween(mc, "_yscale", easeType, begin, end, time, true);
    	}
    }
    the trace first returns "unassigned" but after multiple rollovers it returns false. finally a step in the right direction, but why wont my rollout function execute the expressions in the if statement? thank you for your help so far.

  7. #7
    Junior Member
    Join Date
    Dec 2016
    Posts
    5
    After rummaging through adobe's help section, I located a page that explained global variables..

    Learning ActionScript 2.0 in Adobe Flash / Data and Data Types / About variables / About variables and scope
    I defined the variable within the onClipEvent handler as the following:

    Code:
    _global.flag = false;
    after i declared the variable that way, i was able to reference it by simply typing "flag" how i initially wanted to, even without the "_global." prefix. the trace returns appropriately every time, and my rollout function operates soundly.
    i also read that i couldn't assign data types to a global variable, oddly enough.

    here is my resolved code:
    Code:
    onClipEvent (enterFrame) {
    	_global.flag = false;
    	this.onRollOver = function() {
    		_root.infobox1._visible = true;
    		setProperty(_root.infobox1, _x, getProperty(this, _x));
    		setProperty(_root.infobox1, _y, getProperty(this, _y)-40);
    		this.gotoAndPlay(2);
    		import blipTween;
    		var tween1:blipTween = new blipTween(this);
    		trace(flag);
    	};
    	this.onRelease = function() {
    		if (flag == false) {
    			flag = true;
    		} else {
    			flag = false;
    		}
    	};
    	this.onRollOut = function() {
    		if (flag == false) {
    			_root.infobox1._visible = false;
    			import blipTween;
    			var tween2:blipTween2 = new blipTween2(this);
    		}
    	};
    }
    thank you for your help, i just needed to do more thinking about variable locality... my problem is resolved, sorry for the newbie question!

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