PDA

View Full Version : Main Timeline cotrolled by movieclip currentFrame



LosBenos
October 29th, 2009, 06:36 AM
Here is my code...
I know that the functionality of the addChildToStage and deleteChildFromStage functions works fine because I have tested it here:
http://finga-ninja.com/upload/upload.html
the nav adds a new instance of "player" to the stage and the big red button deletes "player".

I want to start the movie with a mc_CopyBlank on stage and then have the nav issue play(); command to the movie clip held in "player" then have the current frame of that clip trigger the addChildToStage and DeleteChildFromStage functions that I've written here.
The .fla is hosted here:
http://finga-ninja.com/upload/upload.fla
Any ideas as to why this doesn't work.
Feel free to keep the .fla as it's basically a barebones four page site.
(if it ever works)



stop();
mc_nav1.buttonMode = true;
mc_nav2.buttonMode = true;
mc_nav3.buttonMode = true;
mc_nav4.buttonMode = true;
mc_logo.buttonMode = true;
mc_email.buttonMode = true;

mc_nav1.addEventListener(MouseEvent.MOUSE_OVER, reportPosition);
mc_nav1.addEventListener(MouseEvent.MOUSE_OVER, playPlayer);
mc_nav2.addEventListener(MouseEvent.MOUSE_OVER, reportPosition);
mc_nav2.addEventListener(MouseEvent.MOUSE_OVER, playPlayer);
mc_nav3.addEventListener(MouseEvent.MOUSE_OVER, reportPosition);
mc_nav3.addEventListener(MouseEvent.MOUSE_OVER, playPlayer);
mc_nav4.addEventListener(MouseEvent.MOUSE_OVER, reportPosition);
mc_nav4.addEventListener(MouseEvent.MOUSE_OVER, playPlayer);
//reports position of button to "yPosition
function reportPosition(event:MouseEvent):void
{
yPosition = event.target.y;
}


//function that plays the MovieClip contained in the variable "player"
function playPlayer(event:MouseEvent):void
{
player.play();
}




//listens for current frame of movieClip contained in variable "player"
stage.addEventListener(Event.ENTER_FRAME, copyDelete);
function copyDelete(event:Event):void
{
if(MovieClip(player).currentFrame == 20)
{
deleteChildFromStage();
}
}
stage.addEventListener(Event.ENTER_FRAME, copyAdd);
function copyAdd(event:Event):void
{
if(MovieClip(player).currentFrame == 19)
{
addChildToStage();
}
}



//sceneTracer adds is a number that controls what text is added to "player" during the add child function
var sceneTracer:Number = 1;
var player:MovieClip = new MovieClip;
//adds a movie clip to the stage in a variable called "player" different clip depending on yPosition
function addChildToStage():void
{
if (yPosition == 279)
{
player = new mc_CopyBlank();
addChild(player);
player.x = 380;
player.y = 285;
sceneTracer = 1;
}
if (yPosition == 307.25)
{
player = new mc_copy1();
addChild(player);
player.x = 380;
player.y = 285;
sceneTracer = 2;
}
if (yPosition == 335.55)
{
player = new mc_copy2();
addChild(player);
player.x = 380;
player.y = 285;
sceneTracer = 3;
}
if (yPosition == 363.9)
{
player = new mc_copy3();
addChild(player);
player.x = 380;
player.y = 285;
sceneTracer = 4;
}
else
{
player = new mc_CopyBlank();
addChild(player);
player.x = 10;
player.y = 10;
sceneTracer = 1;
}
}
addChildToStage()
//removes "player"
function deleteChildFromStage():void
{
removeChild(player);
}






//Color change
var colorTransformPink:ColorTransform = transform.colorTransform;
var colorTransformWhite:ColorTransform = transform.colorTransform;
colorTransformPink.color = 0xFF3399;
colorTransformWhite.color = 0xFFFFFF;
var yPosition:Number;

stage.addEventListener(Event.ENTER_FRAME, navBar);
function navBar(event:Event):void
{
if(sceneTracer == 1)
{
mc_nav1.transform.colorTransform = colorTransformPink;
mc_nav2.transform.colorTransform = colorTransformWhite;
mc_nav3.transform.colorTransform = colorTransformWhite;
mc_nav4.transform.colorTransform = colorTransformWhite;
}
if(sceneTracer == 2)
{
mc_nav1.transform.colorTransform = colorTransformWhite;
mc_nav2.transform.colorTransform = colorTransformPink;
mc_nav3.transform.colorTransform = colorTransformWhite;
mc_nav4.transform.colorTransform = colorTransformWhite;
}
if(sceneTracer == 3)
{
mc_nav1.transform.colorTransform = colorTransformWhite;
mc_nav2.transform.colorTransform = colorTransformWhite;
mc_nav3.transform.colorTransform = colorTransformPink;
mc_nav4.transform.colorTransform = colorTransformWhite;
}
if(sceneTracer == 4)
{
mc_nav1.transform.colorTransform = colorTransformWhite;
mc_nav2.transform.colorTransform = colorTransformWhite;
mc_nav3.transform.colorTransform = colorTransformWhite;
mc_nav4.transform.colorTransform = colorTransformPink;
}
}

LosBenos
October 29th, 2009, 07:25 PM
here's the working code
here's the url of the final file
www.finga-ninja.com/brand/thebrandagency.html

in future if you can't come up with the answer just don't post a reply yeah.
:-)


stop();
var player:MovieClip = new MovieClip;
var yPosition:Number = 279;
var colorTransformPink:ColorTransform = transform.colorTransform;
var colorTransformWhite:ColorTransform = transform.colorTransform;
colorTransformPink.color = 0xFF3399;
colorTransformWhite.color = 0xFFFFFF;
button1.buttonMode = true;
button2.buttonMode = true;
button3.buttonMode = true;
button4.buttonMode = true;


//runs at start to add initial movie clip
function addPlayerStart():void
{
player = new mc_copyBlank();
addChild(player);
player.x = 380;
player.y = 285;
}
addPlayerStart();




//Plays movieClip inside variable "player"
button1.addEventListener(MouseEvent.MOUSE_OVER, playPlayer);
button2.addEventListener(MouseEvent.MOUSE_OVER, playPlayer);
button3.addEventListener(MouseEvent.MOUSE_OVER, playPlayer);
button4.addEventListener(MouseEvent.MOUSE_OVER, playPlayer);

function playPlayer(event:MouseEvent):void
{
player.play();
yPosition = event.target.y
}




//Listens for currentFrame == 30 in the variable "player" and then calls function 'deletePlayer"
stage.addEventListener(Event.ENTER_FRAME, deletePlayer);
function deletePlayer(event:Event):void
{
if(MovieClip(player).currentFrame == 20)
{
deleteClip();
}
if(MovieClip(player).currentFrame == 20)
{
addPlayer();
}
}



//delete's player and hopefully the movieClip it holds from the stage
function deleteClip():void
{
removeChild(player);
}



//adds variable "player" to the stage and loads a movieClip into it
function addPlayer():void
{
if (yPosition == 279)
{
player = new mc_copyBlank();
addChild(player);
player.x = 380;
player.y = 285;
}
if (yPosition == 307.25)
{
player = new mc_copy1();
addChild(player);
player.x = 380;
player.y = 285;
}
if (yPosition == 335.55)
{
player = new mc_copy2();
addChild(player);
player.x = 380;
player.y = 285;
}
if (yPosition == 363.9)
{
player = new mc_copy3();
addChild(player);
player.x = 380;
player.y = 285;
}
}


stage.addEventListener(Event.ENTER_FRAME, navColour);
function navColour(event:Event):void
{
if(yPosition == 279)
{
button1.transform.colorTransform = colorTransformPink;
button2.transform.colorTransform = colorTransformWhite;
button3.transform.colorTransform = colorTransformWhite;
button4.transform.colorTransform = colorTransformWhite;
}
if(yPosition == 307.25)
{
button1.transform.colorTransform = colorTransformWhite;
button2.transform.colorTransform = colorTransformPink;
button3.transform.colorTransform = colorTransformWhite;
button4.transform.colorTransform = colorTransformWhite;
}
if(yPosition == 335.55)
{
button1.transform.colorTransform = colorTransformWhite;
button2.transform.colorTransform = colorTransformWhite;
button3.transform.colorTransform = colorTransformPink;
button4.transform.colorTransform = colorTransformWhite;
}
if(yPosition == 363.9)
{
button1.transform.colorTransform = colorTransformWhite;
button2.transform.colorTransform = colorTransformWhite;
button3.transform.colorTransform = colorTransformWhite;
button4.transform.colorTransform = colorTransformPink;
}
}

LosBenos
October 30th, 2009, 05:12 AM
it's more like saying...

at frame 30 delete a variable called player from the stage and replace it with a variable called player containing one of four movieClips depending on the yPosition of the button that triggered the animation in the first place.

If you can't understand that then maybe you shouldn't be posting here.
Your conditional statement does save 8 lines of code but that's all you have to offer.
As for using some of your ideas... I got your message after I returned from work with a completed version so that couldn't have happened really.
I glanced at your message and thought "****" then replied with my working code.
It's really very simple...
feel free to copy it and use it in your own work

LosBenos
October 30th, 2009, 06:10 AM
if you work at it enough you can get the mouse over one line of text and highlight it during the 10 frames of fade in animation resulting in a button being highlighted and the wrong text being displayed which is why I made them clickable too.
I'll add a boolean value so that the buttons aren't functional during the fade in of the text but I'm having the day off now.
This is my first as3 project ever with no classes, no books, and no history of web development outside of html and css and frankly I need a break.

LosBenos
October 30th, 2009, 04:59 PM
Thanks for that,
it's a good effort but the colour changes as soon as the mouse rolls out of the button and the copy dissapears. It's really important that they stay as they are once they've been triggered which is why I've done it so that the button reports it's yPosition as an identifier and then I call functions on the last frame of the animation and I call a new one to the stage based on the yPosition of the current button.

LosBenos
October 30th, 2009, 05:00 PM
Sorry if that last post was a bit garbled...
spliff

LosBenos
November 2nd, 2009, 05:38 AM
Not at all
I totally understand that the way you've written your code is a more concise way of writing.
The point really though is that your code doesn't do what the client wants so although it's very geeky it's kinda useless.
I'll be using my code and simply removing event listeners if player.currentFrame =< 10
I may typed out the code for each button manually as opposed to using loops or arrays to declare the same thing with less code but "the point" is to give the client what they want so your code although pretty is an epic fail

LosBenos
November 2nd, 2009, 05:51 AM
<sigh>
the code works fine now it has the event listener removed for the first 10 frames of animation.

The movie clip plays and then stops on a set frame.
The buttons all just say "play();" to whichever movie clip is on the stage.
At the last frame of the movie clip the code removes "player" from the stage and then adds it back again but containing a different movie clip dependant on the button that was pressed (hovered) to trigger the change.
As the text fades in the buttons are disabled for just less than a second to prevent "bugs"

works fine
everyone's happy
client loves it
no bugs

Didn't use your methods or respect your code.
Just keep posting here though if you really want to have the last say mate, I'll unsubscribe from this thread now.
Good luck in the future