Skip to main content
Inspiring
December 11, 2007
Answered

If mc._x = __ not working

  • December 11, 2007
  • 8 replies
  • 637 views
Hey I'm trying to run a code which motion tweens an mc off the stage, and only then does it tween an mc onto the stage. Im using the following script where _x = -200 is the position when it is off the stage.

topbar_box.onRelease = function() {
var moveSectionX:Tween = new Tween(_root.content.section_holder, "_x", Strong.easeIn, 61, -200, 2, true);
var moveSectionY:Tween = new Tween(_root.content.section_holder, "_y", Strong.easeIn, -25, 768, 2, true);
if (_root.content.section_holder._x = -200) {
loadMovie("about_section.png", _root.content.section_holder);
var moveSectionX:Tween = new Tween(_root.content.section_holder, "_x", Strong.easeOut, 500, 22, 2, true);
var moveSectionY:Tween = new Tween(_root.content.section_holder, "_y", Strong.easeOut, -500, -7, 2, true);

It loads the new file into the mc before it has a chance to move off the stage. I tried loading the new file into a new empty mc, and that works, however the new file comes onto the stage too early and doing it this way would leave me with too many empty mcs to load files into.

Cheers
B
This topic has been closed for replies.
Correct answer bartonsmith
For anyone reading this I ended up using setInterval to wait a certain time until it executed the next script.

myFutureFunction = function() {

// setInterval will repeat every XX seconds if we don't clear it here...

clearInterval(handle);

// future lines of code go here...

}


// execute some code here...

// Then use setInterval to schedule myFutureFunction 4 seconds in the future

handle = setInterval(myFutureFunction, 4*1000);

From flashkit.com

Cheers

8 replies

kglad
Community Expert
Community Expert
December 12, 2007
you must define that method in the topbar_box function because you made moveSectionX local to your function.
kglad
Community Expert
Community Expert
December 12, 2007
if you needed to check that _x property after the tween was complete you should just use the onMotionFinished() method of the tween class.
Inspiring
December 12, 2007
Good thinking. It doesn't seem to be working though. What's new. Even though I have another file where it uses the onMotionFinished method and works...
bartonsmithAuthorCorrect answer
Inspiring
December 12, 2007
For anyone reading this I ended up using setInterval to wait a certain time until it executed the next script.

myFutureFunction = function() {

// setInterval will repeat every XX seconds if we don't clear it here...

clearInterval(handle);

// future lines of code go here...

}


// execute some code here...

// Then use setInterval to schedule myFutureFunction 4 seconds in the future

handle = setInterval(myFutureFunction, 4*1000);

From flashkit.com

Cheers
kglad
Community Expert
Community Expert
December 11, 2007
that _x property is probably not exactly -200. use Math.abs() to check if the _x property is close enough to -200 to trigger your load.
Inspiring
December 11, 2007
hey no luck their eitehr kglad... i did it like: if (_root.content.section_holder._x == Math.abs(-200)) {
Inspiring
December 11, 2007
ha so you have to download it hey...
i put it in the First Run > Classes > FP8 folder,
called import FP8.caurina.transitions.*;
but it still doesn't work?
still im curious if there is a solution using time...
Inspiring
December 11, 2007
great cheers kglad. that worked, but now it sits at -200 and doesnt load the new files into that mc and ease in...
any idea why?
kglad
Community Expert
Community Expert
December 11, 2007
use double equal (==) to test for equality. and use the attach code option to display code in this forum.
Inspiring
December 11, 2007
>>if (_root.content.section_holder._x = -200) {

Here you're assigning -200 to _x - you want a double-equal to test for
equality:

if (_root.content.section_holder._x == -200) {

However this still isn't going to work, as your test only happens one time,
and your clip isn't going to be at -200 until the tween finishes. I don't
use the built in tweening stuff, but you may want to look at something like
Tweener, or Fuse where you can define a callback to execute once the tween
completes:

Tweener.addTween(_root.content.section_holder, {_x:-200, time:2,
transition:"strong.easein", onComplete:offStage});

function offStage(){
//transition completed
}


--
Dave -
Head Developer
http://www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/


Inspiring
December 11, 2007
Hey, what's Tweener? There is nothing in help, and I tired the following script but it didnt work:

import mx.transitions.Tween;
import mx.transitions.easing.*;

function offStage() {
loadMovie("about_image.png", _root.content.image_holder);
var moveImageX:Tween = new Tween(_root.content.image_holder, "_x", Strong.easeOut, Stage.width, 66, 3, true);
var moveImageY:Tween = new Tween(_root.content.image_holder, "_y", Strong.easeOut, 630, 150, 3, true);
unloadMovie(_root.content.section_holder2);
}

topbar_box.onRelease = function() {
Tweener.addTween(_root.content.section_holder,{_x:-200, time:2, transition:"strong.easein", onComplete:offStage});
Tweener.addTween(_root.content.section_holder,{_y:768, time:2, transition:"strong.easein"});
};

What if you did it so that instead of checking for _x it waited for 2secs - or any defined time - since we know it will take 2 seconds to complete the transition...