Copy link to clipboard
Copied
I'm in need of some help!
Quick background -- I'm the guy at work who has the most basic, basic, basic understanding of Flash and has it installed. That makes me the "go to" guy now. I've been avoiding AS3 for a few years now because I'm not a software engineer and my coding knowledge is pretty limited. I could google around for an hour and getting something working in AS2. Not so much with AS3. We've recently upgraded to Flash CC and had all previous versions removed, so now I have no choice. I can follow directions but the technical jargon associated with AS3 is a steep learning curve for me when I do this kind of stuff maybe twice a year.
Now, what I'm trying to accomplish:
It's stupid simple. I have a flash web-banner. The background is a static PNG image. It has a countdown clock to a set date. I need the whole banner to function as a button so when you click it, it takes the user to a website. That's it. That's all I need. I've been able to do this in AS2 before without too much of a fight.
So I've accomplished the countdown timer using the script from this site:
http://blog.anselmbradford.com/2009/08/03/creating-a-date-countdown-timer-in-actionscript-3-flash/
It works by referencing outside scripted classes. It took me a little bit of tinkering, but I got it working, no problem.
So then I go to make a button. I create a button object. Make it invisible, set it on a layer above everything else. I apply this code to the actions:
MyButton.addEventListener(MouseEvent.CLICK,f);
function f(e:Event){
navigateToURL(new URLRequest("http://www.adobe.com")); // use the url of your choice.
}
And then it breaks. The SWF throws errors and won't compile.
First it says:
1180: Call to a possibly undefined method Event.
So I import flash.events.Event. Then I get:
1180: Call to a possibly undefined method navigateToURL.
1180: Call to a possibly undefined method URLRequest.
1180: Call to a possibly undefined method addFrameScript.
1120: Access of undefined property MouseEvent.
So I add:
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.events.MouseEvent;
That clears all errors except the 1180: addFrameScript. From what I've read, when there's an outside class being used, I can't apply action script in a frame on the timeline?
This is so far above my head. I tried for hours yesterday to figure out a way to add in the button script to the main class but the closest I got was compile errors about my button never being defined. I have no idea what I'm doing here and why it's so hard to make two things work at the same time in AS3. I'm just frustrated with the whole thing now.
Could someone take pity on me and explain to me what I need to do to get this button working? Try to use small words and talk to me like I'm the village idiot, which is how I'm feeling right now.
Thanks!
1 Correct answer
change that to the following and retest:
...
Joshua Fowler wrote:
I think you're correct. Under the Publish settings of the document, that's what "Class" points to.
Here's the first main section of the code:
package com.anselmbradford
{
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Main extends MovieClip
{
/**
* Create a new CountDown object, listen for updates and pass it the date to countdown to.
*/
public function Mai
Copy link to clipboard
Copied
you have code on your timeline somewhere and your document class is extending the Sprite class.
either remove the timeline code or have your document class extend the MovieClip class.
Copy link to clipboard
Copied
Thanks for the response!
I had seen errors related to "Sprite class" but I don't actually know what this refers to. I also don't have an understanding of what you mean when you talk about extending a class. I apologize but I don't have any knowledge of how this stuff runs under the hood. I used Flash to animate, not to do useful coding stuff.
So if I remove the code from the timeline, does that mean I need to add the code into the Main.as file, or create an additional .as file and link to that from Main? Is there any learning resource with example code or a clear explanation of how the MovieClip class relates to what I'm trying to accomplish? I'm willing to look it up and learn but the jargon has me pretty confused so I don't really know what terms I'm searching for. For instance, the only thing I know about MovieClip is that I see that option when I press F8 to turn an object into a Movie Clip, Graphic, or Button. Past that, I have no idea how that relates to a class or why one line of code precludes all others…
Copy link to clipboard
Copied
Main.as is probably your document class.
copy and paste the first 10 or so lines of code from that class.
Copy link to clipboard
Copied
I think you're correct. Under the Publish settings of the document, that's what "Class" points to.
Here's the first main section of the code:
package com.anselmbradford
{
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Main extends Sprite
{
/**
* Create a new CountDown object, listen for updates and pass it the date to countdown to.
*/
public function Main()
{
var cd:CountDown = new CountDown();
cd.addEventListener( CountDownEvent.UPDATE , _updateDisplay );
cd.init( new Date(2015,3,9,20,00) );
}
/**
* Update the display.
*/
private function _updateDisplay( evt:CountDownEvent ) : void
Does this look correct?
Thanks again!
Copy link to clipboard
Copied
change that to the following and retest:
Joshua Fowler wrote:
I think you're correct. Under the Publish settings of the document, that's what "Class" points to.
Here's the first main section of the code:
package com.anselmbradford
{
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Main extends MovieClip
{
/**
* Create a new CountDown object, listen for updates and pass it the date to countdown to.
*/
public function Main()
{
var cd:CountDown = new CountDown();
cd.addEventListener( CountDownEvent.UPDATE , _updateDisplay );
cd.init( new Date(2015,3,9,20,00) );
}
/**
* Update the display.
*/
private function _updateDisplay( evt:CountDownEvent ) : void
Does this look correct?
Thanks again!
Copy link to clipboard
Copied
You are both a scholar and a gentlemen, kglad.
That did the trick. Thank you so much for your patience!
Just for future reference, what was the difference between extending a sprite and extending a movie clip? Is there anywhere that explains that in clear terms?
Anyway, Thank You again!
Copy link to clipboard
Copied
a sprite has no timeline so you can't put code on its timeline.
a movieclip has a timeline so you can put code on its timeline.

