Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

startDrag operating strangely

When I place a startDrag statement in an if statement, it gets called whatever the clause is.

It's very strange - in the code example drag_time is "false" before the if statement, but it gets set to whatever the if statement's clause is (in this case "testingtesting"!) and so whatever is inside the if gets called.

the first trace is "false" the second is "testingtesting". Even if I change the clause to equal "butterfly", say, then it gets set to that!

Where am I going wrong?
paintings_loader_mc.onPress = function() {
	trace(_root.chooser_mc.drag_time)
	if (_root.chooser_mc.drag_time = "testingtesting") {
		trace(_root.chooser_mc.drag_time)
		_root.paintings_loader_mc.startDrag();
	}
}

Open in new window

0
corin_pearce
Asked:
corin_pearce
1 Solution
 
ruijietanCommented:
For comparing strings you use the == (equality comparison) operator , not the = (assignment) operator.

What your code currently does is that it sets drag_time to "testingtesting" instead of comparing it.

Switch = to == and it should work. :D
paintings_loader_mc.onPress = function() {
        trace(_root.chooser_mc.drag_time)
        if (_root.chooser_mc.drag_time == "testingtesting") { // drag_time == "testingtesting"
                trace(_root.chooser_mc.drag_time)
                _root.paintings_loader_mc.startDrag();
        }
}

Open in new window

0
 
corin_pearceAuthor Commented:
wow that was simple, how silly of me - thanks!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now