By the way - viewtopic.php?f=29&t=2370
I try to write a little topic about AS2 <-> AS3 - may be you will find some thing interesting - there are some changes in hitTest / working with php and with colours in AS3.
OwnerOfSuccuby Wrote:By the way - viewtopic.php?f=29&t=2370 I try to write a little topic about AS2 <-> AS3 - may be you will find some thing interesting - there are some changes in hitTest / working with php and with colours in AS3.
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Dress extends MovieClip{
public function Dress() {
this.addEventListener(Event.ENTER_FRAME, DressOnEnterFrame)
}
protected function DressOnEnterFrame(e:Event):void{
if(this is *VEST CLASS NAME*)
DressVest();
else if (this is *ARM CLASS NAME*)
DressArm();
else if (this is *FOOT CLASS NAME*)
DressFoot();
else
gotoAndStop(GetDress());
}
protected function cRoot():Game{ // Convert root to game.
return (root as Game);
}
protected function GetDress():String{
return (cRoot().DressSel[ cRoot().DressNum ] as String); // May have to try this code if return throws an error
}
protected function DressVest():void{
if( currentFrameLabel != GetDress() ){
if ( cRoot().clothes_vest_remove && cRoot().DressNum != 3)
gotoAndStop("naked");
else
gotoAndStop(GetDress());
}
}
protected function DressFoot():void{
// Foot dress code
}
protected function DressArm():void{
// Arm dress code
}
}
}
if(this is *VEST CLASS NAME*)
becomes
if(this is BodyClothes)
AnotherArrow Wrote:Well, in my experimenting, I found a way to find out how to identify a symbol without making multiple inherited class.
//QUICK placement just before the frame is drawn!
if (_root.gloves_type=="None")
gotoAndStop("Naked");
else
gotoAndStop(_root.DressSel[_root.DressNum]);
//ABOVE must not be executed anymore while the SAME MC is acting (like in MOVING pose). Thats why I use this in a 'control' frame (currentFrame will never select it again.
if (!once)
{
once=true;
onEnterFrame=function()
{
if (currentlabel!=_root.DressSel[_root.DressNum])
{
if (_root.DressNum=="13")
{
if (_root.gloves_type=="None")
gotoAndStop("Naked");
else
gotoAndStop(_root.DressSel[_root.DressNum]);
}
else
gotoAndStop(_root.DressSel[_root.DressNum]);
}
currentlabel=_root.DressSel[_root.DressNum];
}
}
Avoiding it to run getDress at every frame, in case the global DressSel hasnt changed at all (e.g. the player is just moving the character without changing her outfits or making her lose one).
How I do this in AS2:
(first frame of any clothing part MC):
For Function OnEnterFrame
If current label is not the current dress
check if the gloves are worn
if no, make "naked"
if so, set clothes
else (current label is the current dress)
put that dress back on again
package {
import flash.display.MovieClip;
import flash.events.Event;
public class Dress extends MovieClip{
public function Dress() {
this.addEventListener(Event.ENTER_FRAME, DressOnEnterFrame)
}
protected function DressOnEnterFrame(e:Event):void{
if(this is *VEST CLASS NAME*)
DressVest();
else if (this is *Glove CLASS NAME*)
DressGloves();
else if (this is *FOOT CLASS NAME*)
DressFoot();
else
if( currentFrameLabel != GetDress() )
gotoAndStop(GetDress());
}
protected function cRoot():Game{ return (root as Game);}
protected function GetDress():String{ return (cRoot().DressSel[ cRoot().DressNum ] as String);}
protected function DressVest():void{
if( currentFrameLabel != GetDress() ){
if ( cRoot().clothes_vest_remove && cRoot().DressNum != 3)
gotoAndStop("naked");
else
gotoAndStop(GetDress());
}
}
/************** NEW CODE HERE **************************/
protected function DressGloves():void{
if( currentFrameLabel != GetDress() ){
if ( cRoot().gloves_type == "None")
gotoAndStop("naked");
else
gotoAndStop(GetDress());
}
}
/******************************************************/
protected function DressFoot():void{
// Foot dress code
}
}
}
AnotherArrow Wrote:I can't think of a way ATM, cause you're still doing the "child ask parent" method. Even if you have a boolean variable like "HasDressChange" as a global, the Code is still going to have to ask the parent (or in this case the root) "do the clothes need to be changed".
AnotherArrow Wrote: /************** NEW CODE HERE **************************/
protected function DressGloves():void{
if( currentFrameLabel != GetDress() ){
if ( cRoot().gloves_type == "None")
gotoAndStop("naked");
else
gotoAndStop(GetDress());
}
}
/******************************************************/
//QUICK placement just before the frame is drawn!
if (_root.gloves_type=="None")
gotoAndStop("Naked");
else
gotoAndStop(_root.DressSel[_root.DressNum]);
//ABOVE must not be executed anymore while the SAME MC is acting (like in MOVING pose). Thats why I use this in a 'control' frame (currentFrame will never select it again.
//I use 'once' to ENSURE it wont be executed again, just in an ALIEN case that this frame is called again in the same instance (e.g. player keeping the character MOVING all the time)
if (!once)
{
once=true;
onEnterFrame=function()
{
if (currentlabel!=_root.DressSel[_root.DressNum])
{
if (_root.DressNum=="13")
{
if (_root.gloves_type=="None")
gotoAndStop("Naked");
else
gotoAndStop(_root.DressSel[_root.DressNum]);
}
else
gotoAndStop(_root.DressSel[_root.DressNum]);
}
currentlabel=_root.DressSel[_root.DressNum];
}
}
But, in order to avoid blinking in the first frame, we can put ' gotoAndStop(GetDress())' in the beginning, outside onEnterFrame, in a way its played only once in each dress MC. In AS2, using the code above I've shown you, I use gotoAndStop(DressSel[DressNum]) once, because it needs to point to the correct frame just before its drawn on the screen. After this, the code is not executed anymore because its OUTSIDE the onEnterFrame. (sorry I havent put the code above there).
public function Dress() {
this.addEventListener(Event.ADDED_TO_STAGE, DressOnEnterFrame)
this.addEventListener(Event.ENTER_FRAME, DressOnEnterFrame)
}
AnotherArrow Wrote:i always forget about that glitch.... here... modify the constructor
Please read above again, I've updated some text and I've put an image to clarify, thanks
onAddtoStage=function(){
//code.....
}
But, in a normal approach, every new frame WILL trigger getDress, even if not needed. Using the currentFrameLabel, we trigger getDress once in a given animation.
That because, when the character is stopped, even with animation (tween ones), all body , legs, arms instances will be affected, even if the timeline has 100, 1000 frames.
Using onEnterFrame without currentFrameLabel, it will always set getDress there, which is not necessary (I've tested here in AS2).
protected function DressOnEnterFrame(e:Event):void{
if(this is *VEST CLASS NAME*)
DressVest(); //<------ runs if symbol is a vest
else if (this is *Glove CLASS NAME*)
DressGloves(); //<------------ runs if symbol is a glove
else if (this is *FOOT CLASS NAME*)
DressFoot(); // <----------- runs if symbol is a boot
else
if( currentFrameLabel != GetDress() ) // <----------- this should prevent it from calling gotoAndStop over and over.
gotoAndStop(GetDress());
}
But, in order to avoid blinking in the first frame, we can put ' gotoAndStop(GetDress())' in the beginning, outside onEnterFrame, in a way its played only once in each dress MC. In AS2, using the code above I've shown you, I use gotoAndStop(DressSel[DressNum]) once, because it needs to point to the correct frame just before its drawn on the screen. After this, the code is not executed anymore because its OUTSIDE the onEnterFrame. (sorry I havent put the code above there).
AnotherArrow Wrote:Reread... but maybe i'm still missing the problem. You may need to highlight the questions in the post to help me... I was never good at English.
AnotherArrow Wrote:1) Are we coding for as2 or as3?
AnotherArrow Wrote:You are trying to not run the gotoAndStop over and over, right?
AnotherArrow Wrote:In the DressOnEnterFrame
- Code: Select All Code
protected function DressOnEnterFrame(e:Event):void{
if(this is *VEST CLASS NAME*)
DressVest(); //<------ runs if symbol is a vest
else if (this is *Glove CLASS NAME*)
DressGloves(); //<------------ runs if symbol is a glove
else if (this is *FOOT CLASS NAME*)
DressFoot(); // <----------- runs if symbol is a boot
else
if( currentFrameLabel != GetDress() ) // <----------- this should prevent it from calling gotoAndStop over and over.
gotoAndStop(GetDress());
}
AnotherArrow Wrote:The new listener I added to the constructor will run once the symbol enters the stage... so when the character first spawns there, it will the DressOnEnterFrame before rendering to screen prevent the "blink".
AnotherArrow Wrote:or.. as i continue to reread that statement... Are you asking how to stop onEnterFrame code entirely from running once its at the correct frame?
AnotherArrow Wrote:You're just trying to stop all the calls to "gotoAndStop", right? the onEnterframe should do that.
Users browsing this forum: No registered users