To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Actionscript 3.0

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 11-03-2009, 05:24 AM   #1
Jbard
Member
 
Join Date: Jun 2009
Posts: 49
resolved [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();
    
    }
Jbard is offline   Reply With Quote
Old 11-03-2009, 03:23 PM   #2
jAQUAN
it's automatic
 
jAQUAN's Avatar
 
Join Date: Jul 2000
Location: NaN
Posts: 2,000
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
}
__________________
I approve this message.
AS3SOURCE: @ @ @ @
SD | fk css | Believe the HYPE | I tweet.
jAQUAN is offline   Reply With Quote
Old 11-03-2009, 03:50 PM   #3
bgregus
Senior Member
 
Join Date: Jul 2001
Location: San Jose California
Posts: 127
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?
__________________
bgregus is offline   Reply With Quote
Old 11-03-2009, 04:03 PM   #4
Jbard
Member
 
Join Date: Jun 2009
Posts: 49
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.
Jbard is offline   Reply With Quote
Old 11-03-2009, 04:10 PM   #5
bgregus
Senior Member
 
Join Date: Jul 2001
Location: San Jose California
Posts: 127
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.
__________________
bgregus is offline   Reply With Quote
Old 11-03-2009, 04:21 PM   #6
Jbard
Member
 
Join Date: Jun 2009
Posts: 49
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.
Jbard is offline   Reply With Quote
Old 11-03-2009, 04:31 PM   #7
bgregus
Senior Member
 
Join Date: Jul 2001
Location: San Jose California
Posts: 127
wacky
__________________
bgregus is offline   Reply With Quote
Old 11-03-2009, 04:48 PM   #8
AttackRabbit
rabid_Delineator
 
AttackRabbit's Avatar
 
Join Date: Dec 2003
Location: Orlando, Florida
Posts: 307
what packages are you importing ?
AttackRabbit is offline   Reply With Quote
Old 11-03-2009, 06:20 PM   #9
bgregus
Senior Member
 
Join Date: Jul 2001
Location: San Jose California
Posts: 127
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);
__________________
bgregus is offline   Reply With Quote
Old 11-03-2009, 08:21 PM   #10
Jbard
Member
 
Join Date: Jun 2009
Posts: 49
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.*;
Jbard is offline   Reply With Quote
Old 11-04-2009, 12:49 PM   #11
bgregus
Senior Member
 
Join Date: Jul 2001
Location: San Jose California
Posts: 127
Quote:
Originally Posted by Jbard View Post
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?
__________________
bgregus is offline   Reply With Quote
Old 11-04-2009, 02:54 PM   #12
AttackRabbit
rabid_Delineator
 
AttackRabbit's Avatar
 
Join Date: Dec 2003
Location: Orlando, Florida
Posts: 307
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.
AttackRabbit is offline   Reply With Quote
Old 11-04-2009, 06:17 PM   #13
Jbard
Member
 
Join Date: Jun 2009
Posts: 49
Wink

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
Jbard is offline   Reply With Quote
Old 11-04-2009, 07:27 PM   #14
bgregus
Senior Member
 
Join Date: Jul 2001
Location: San Jose California
Posts: 127
nice!
__________________
bgregus is offline   Reply With Quote
Old 11-05-2009, 11:24 AM   #15
jAQUAN
it's automatic
 
jAQUAN's Avatar
 
Join Date: Jul 2000
Location: NaN
Posts: 2,000
ADDED_TO_STAGE events were creates to avoid having to do just that.
__________________
I approve this message.
AS3SOURCE: @ @ @ @
SD | fk css | Believe the HYPE | I tweet.
jAQUAN is offline   Reply With Quote
Old 11-05-2009, 12:32 PM   #16
AttackRabbit
rabid_Delineator
 
AttackRabbit's Avatar
 
Join Date: Dec 2003
Location: Orlando, Florida
Posts: 307
cool , mark your thread as resolved
AttackRabbit is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Actionscript 3.0

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:57 AM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.