|
-
[RESOLVED] tweening problem
Hi
I am making a simple image gallery, basically their are 5 pictures positioned on the stage and when one is clicked it centers itself on the screen then expands its height and width to fill the stage, most of the time this works fine but for some reason the very first time an image is clicked it doesn't center itself vertically only horizontally, I'm sure this must be a simple problem i just can't pick it up.
here is my code:
PHP Code:
pic1.addEventListener(MouseEvent.MOUSE_DOWN, movePic);
pic2.addEventListener(MouseEvent.MOUSE_DOWN, movePic);
pic3.addEventListener(MouseEvent.MOUSE_DOWN, movePic);
pic4.addEventListener(MouseEvent.MOUSE_DOWN, movePic);
pic5.addEventListener(MouseEvent.MOUSE_DOWN, movePic);
var myTimer:Timer = new Timer(1000, 1);
myTimer.addEventListener(TimerEvent.TIMER, growWidth);
var myTimer2:Timer = new Timer(1000, 1);
myTimer2.addEventListener(TimerEvent.TIMER, growHeight);
var lisTimer:Timer = new Timer(1500);
lisTimer.addEventListener(TimerEvent.TIMER, addlistener);
var lisTimer2:Timer = new Timer(2500);
lisTimer2.addEventListener(TimerEvent.TIMER, addlistener2);
function addlistener(e:TimerEvent):void{
mc.addEventListener(MouseEvent.MOUSE_DOWN, closePic);
}
function addlistener2(e:TimerEvent):void{
mc.addEventListener(MouseEvent.MOUSE_DOWN, movePic);
}
var mc:Object;
var oX:Number;
var oY:Number;
var oW:Number;
var oH:Number;
function movePic(evt:MouseEvent):void{
if(lisTimer2.running){
lisTimer2.stop();
}
mc = evt.target;
mc.removeEventListener(MouseEvent.MOUSE_DOWN, movePic);
oX = mc.x;
oY = mc.y;
oW = mc.width;
oH = mc.height;
mc.parent.setChildIndex(mc, mc.parent.numChildren-1);
centerPic();
myTimer.start();
}
function growHeight(evt:TimerEvent):void{
import fl.transitions.Tween;
import fl.transitions.easing.*;
var myTweenHeight:Tween = new Tween(mc, "height", Strong.easeOut, mc.height, stage.stageHeight, 3, true);
lisTimer.start();
}
function growWidth(evt:TimerEvent):void{
import fl.transitions.Tween;
import fl.transitions.easing.*;
var myTweenWidth:Tween = new Tween(mc, "width", Strong.easeOut, mc.width, stage.stageWidth, 3, true);
myTimer2.start();
myTimer.stop();
}
var stagew:Number = (stage.stageWidth/2);
var stageh:Number =(stage.stageHeight/2);
function centerPic():void{
import fl.transitions.Tween;
import fl.transitions.easing.*;
var myTweenX:Tween = new Tween(mc, "x", Strong.easeOut, mc.x,stagew , 2, true);
var myTweenY:Tween = new Tween(mc, "y", Strong.easeOut, mc.y,stageh , 2, true);
}
function closePic(evt:MouseEvent):void{
lisTimer.stop();
mc.removeEventListener(MouseEvent.MOUSE_DOWN, closePic);
import fl.transitions.Tween;
import fl.transitions.easing.*;
var myTweenWidth:Tween = new Tween(mc, "width", Strong.easeIn, mc.width, oW, 2, true);
var myTweenHeight:Tween = new Tween(mc, "height", Strong.easeIn, mc.height, oH, 2, true);
var myTweenX:Tween = new Tween(mc, "x", Strong.easeIn, stagew, oX, 2, true);
var myTweenY:Tween = new Tween(mc, "y", Strong.easeIn, stageh, oY, 2, true);
lisTimer2.start();
}
-
Total Universe Mod
Try adding a trace right after you set stagew and stagey:
PHP Code:
var stagew:Number = (stage.stageWidth/2); var stageh:Number =(stage.stageHeight/2); trace("stagew:", stagew, "\nstageh:", stageh);
If you get null its because you are recording those values before your main object has been added to the stage. There is no longer a global Stage object like in as2. Instead each descendant of DisplayObject has a .stage property but only when the object is actually on a display list.
The way to ensure there's a stage property to read is to set up a listener for ADDED_TO_STAGE where you handler calls and init function that starts up your movie.
PHP Code:
addEventListener(Event.ADDED_TO_STAGE, onAdded);
function onAdded(e:Event):void{ removeEventListener(Event.ADDED_TO_STAGE, onAdded); init(); }
function init():void{ //everything else }
-
Jbard - I noticed when creating dynamic boarders that preview (ctrl+enter) will short the height value of the stage. For example if the stage height was 200px the boarder would show up as 100px in preview. Viewing the file by double clicking on the swf or putting it in a page things look normal.
Could this preview bug be the issue?
-
hmmm, well i seem to have the opposite problem. if i use (ctrl + enter) everything works fine. But when i use the swf thats when i get my problems.
-
Have you tried what jAQUAN mentioned? Drop a dynamic text box onto the stage and then see what it's spitting out when the file is embedded into your html.
I noticed that AS3 stage calls have problems if you are exporting as Flash Player 9. If that is the case you might consider hard coding your stage values if it's only the images that are what differs in size.
-
ok this is really wierd, i just added the trace values and they would always appear as the correct number and everything would work fine, then i tried in my swf and i would still get the error. so i added two text fields which displayed the stagew and stageh properties and i havent got the error in my swf. then i took the text fields away and got the error straight away. i dont know how these text fields could stop the error but they appear to be doing so.
-
wacky
-
rabid_Delineator
what packages are you importing ?
-
This seems to work for my stage object problem. Maybe it might work for yours.
PHP Code:
var bugFix = function(){ // do stuff // make sure stage variables are in here as well }; setTimeout(bugFix,1);
-
at the moment i have this writen in the main time line so the only things i import are these:
import fl.transitions.Tween;
import fl.transitions.easing.*;
-
 Originally Posted by Jbard
ok this is really wierd, i just added the trace values and they would always appear as the correct number and everything would work fine, then i tried in my swf and i would still get the error. so i added two text fields which displayed the stagew and stageh properties and i havent got the error in my swf. then i took the text fields away and got the error straight away. i dont know how these text fields could stop the error but they appear to be doing so.
It's possible the order of execution is screwing things up. The text fields may offset that. How did the setTimeout() work?
-
rabid_Delineator
its definitely an order of operations thing. I wouldnt be surprised if your two vars , stagew and stageh , do not have values yet , at the time in which your timer starts. You are declaring them way down into your code. Try declaring and instantiating them as the very first thing you do.
-
Yes i declared my variables at the top of my code and added a settimeout function and everything seems to be working fine.
Thank you very much for all your help i really appreciate it
-
-
Total Universe Mod
ADDED_TO_STAGE events were creates to avoid having to do just that.
-
rabid_Delineator
cool , mark your thread as resolved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|