Creative COW SIGN IN :: SPONSORS :: ADVERTISING :: ABOUT US :: CONTACT US
Creative COW's LinkedIn GroupCreative COW's Facebook PageCreative COW on TwitterCreative COW's Google+ PageCreative COW on YouTube
ADOBE FLASH:HomeFlash ForumFlash TutorialsFlash Video TutorialsWeb Streaming ForumAdobe FlashPodcast

Re: Problems scripting button links in Flash CS4/AS3.0

COW Forums : Adobe Flash

FAQ   •   VIEW ALL   •   ADD A NEW POST   •   PRINT
Share on Facebook
Respond to this post   •   Return to posts index   •   Read entire thread


demetri tashieRe: Problems scripting button links in Flash CS4/AS3.0
by on Jul 11, 2012 at 2:32:34 pm

the short answer is: you can't name something in code that is not yet available on that frame. actionscript can not see into future frames like that.

the long answer is this:

this is an inherent problem in coding timeline based naviagation, and one of the reasons why it has fallen out of use. that being said, it can of course be done, but with some extra work.

probably the easiest way is to break up the code, and place the relevant pieces on whichever and however many different frames as needed. if your 'proseBtn' appears on frame 100,then the code for that button would also be on frame 100. if your 'poetryBtn' is on frame 150, then the code for that would be on frame 150. doing this carefully can and will make it work. HOWEVER, having code scattered all over the place is seen as being bad form and coding practice ( imagine coming back to it in a few months, or handing it off to someone else to try to work on - it could quickly become overwhelming).

so, a step up from that is to keep all the code in one place( the first frame) and work off of it there. this is where an ENTER_FRAME Event comes into play. attached to the stage, it checks every frame while the timeline is moving ( or 15 times a sceond for a framerate of 15 fps while the timeline is not moving). judiciously used ( add the event for a timeline in motion, and remove it when it is not in motion) it can effectively be used to turn this kind of statement into code:

" if the timeline reached or is passing through frame 100 ( or frame label 'retProse'), then add an event listener to the 'proseBtn' " **

other effective techniques are to use and manipulate the visibility and/or alpha properties. this way everything is actually on the stage at the beginning, and will not throw errors in the coding. the visibility/alpha is truned on and off as needed.

better yet is to abandon the timeline, and make each 'page/section' its own movieclip, or even external swf, which can be added or made visible as needed.

i know that's a lot, and is obviously just a skeletal overview of how to approach this. whichever way you choose, including more advanced methods, you do yourself a favor by thinking through the logic and building a coding strategy around that. in other words, at every stage, you should be able to state what you want happening, and what you don't want happenning. then you can be clear with your coding, and troubleshooting will also be MUCH easier.

if you have specific questions along the way, please ask.

** here is some sample code for illustration:
proseBtn.visible=false;
stage.addEventListener(Event.ENTER_FRAME, checkFrames);
function checkFrames(e:Event):void {

if(currentFrame==100) {
stop();
proseBtn.visible=true;
proseBtn.addEventListener(MouseEvent.CLICK, goProse);
}
}
function goProse(e:MouseEvent):void {

gotoAndStop("retProse");
}


Posts IndexRead Thread
Reply   Like  
Share on Facebook


Current Message Thread:




LOGIN TO REPLY



FORUMSTUTORIALSMAGAZINESTOCKYARDVIDEOSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

Creative COW LinkedIn Group Creative COW Facebook Page Creative COW on Twitter
© 2013 CreativeCOW.net All rights are reserved. - Privacy Policy

[Top]