Sunday, March 28, 2010

Trouble adding a web url link to an...

Hi There,

We're trying to add a simple link to an existing Flash file. There looks to be at least 7 separate .as files and a separate swf that loads the main swf which all seems overly complex for what is essentially a page with six buttons on it.

However, we need to add a URL to some of the text. So we converted the text to a button, added an instance name of %26lt;ssbpurchasetickets_btn%26gt; then added the following Actionscript into the actions layer on the frame the text/button appears:

ssbpurchasetickets_btn.addEventListener(MouseEvent.CLICK, ssbButtonPurchase);

function ssbButtonPurchase(event:MouseEvent):void

{

navigateToURL(new URLRequest(''http://www.url.com/tickets.html''));

}

When we publish the file we get the following error which seems to cascade into a whole bunch more errors:

Description: 1046: Type was not found or was not a compile-time constant: MouseEvent.

Source: function ssbButtonPurchase(event:MouseEvent):void

We added ''ssb'' onto the button and functions to ensure there were no conflicts but the same thing occurred. If we copy the button into a new file everything works so it must be conflicting with something in the main files.

Any help would be MUCH appreciated!!!!

Cheers

Trouble adding a web url link to an...

Check your Publish Settings to make sure they are not set for AS2.

Edit: I should have added that you may want to make sure you are supposed to be using AS3 and that your files are not using AS2.

Trouble adding a web url link to an...

Thanks for the reply Ned,

The file is set to use AS3 and I'm pretty sure the original should be set to AS3 as the .as files look like AS3 syntax to me - here's a sample:

protected function handleWwrdButtonClick(e:ButtonEvent):void {

Browser.open(globalVar.xml.wwrd.item[0].@url, globalVar.xml.wwrd.item[0].@target);

OmnitureTracker.trackFeaturedContentClick('http://www.url.com/movies/international', 'wwrd_button');

timer.stop();

timer.removeEventListener(TimerEvent.TIMER, onTimer);

}

I'm wondering if all the Actionscript has be placed into one of the .as files as there isn't any Actionscript in the Flash project - a part from the odd stop()

Really stuck on this one (I'm not an expert at all) so any help in deciphering the project would be much appreciated.

Cheers

Have tried it in one of the external files but just get the same error.

Having trouble understanding what this error specifically means - is it some kind of conflict with other elements or is it some kind or mistake when defining elements in the script - or none of these?

It seems Flash is now so complex it's basically an object orientated programming language. I can't believe that adding a button is so difficult. After working on this for over 3 hours, I feel small and stupid!

I think you're hitting my weak suit here, class/as files. Is this being done in one of the AS files or one of the fla files??If it is an .as file, what you may need to do is to import the MouseEvent class into the file where you are adding the event listener... which you can probably do using... import flash.events.*; at the start of the file

If it is complaining that it doesn't recognize MouseEvent in an fla file, my experience has been that the Publish Settings aren't set properly for AS3... otherwise, there is no reason for the fla file to be failing to recognize that... it's is reasonable to expect it to fail if the .as file does not import that though.

Thank you so much for responding.

I added the script I posted above to a frame in the actions layer in one of the Flash files (where the button appears). I then removed it and pasted it into the .as file that is named the same as the Flash file - seemed like the right file!

So essentially, I need to somehow get Flash to recognise this event. Can I set up my own .as file that contains my button code and import it somehow? The other thing I cannot find, is where exactly you tell Flash to import these files - is there a way to search for a complete list of functions and files used in a Flash project?

If you added that code to the fla file, in a frame where the button instance is (just the same frame, not necessarily the same layer), then there should be no reason for it to not recognize MouseEvent (except as I already noted regarding the Publish Settings not being set for AS3).?You should not have to import anything for it.?It is only when you are coding in .as files that you need to be sure to import the classes used.

One other thing you might try, just to see if more detailed error info is available... in the Flash section of the Publish Settings, somewhere below where you set the version of AS, there is a checkbox to allow debugging... select that option.?It usually provides a little more info in the error messages with that selected.

OK, just so I don't run around in circles, I need to make absolutely sure this should be a AS3.0 file.

I removed my code and chose AS2.0, then republished. This brought up these types of errors - I'm assuming this mean it should be set to AS3.0 as I get no errors when it's set to AS3.0:

The class or interface 'videoFullButton' could not be loaded.

The class or interface 'videoVolumeArea' could not be loaded.

I'm wondering if none of the default classes are being loaded which might mean my MouseEvents might not work?

Have looked into the classes being loaded in the main.as file and they are:

import flash.display.MovieClip;

import flash.events.Event;

import flash.text.TextFieldAutoSize;

import flash.text.TextField;

import flash.net.URLRequest;

import flash.net.navigateToURL;

import flash.external.ExternalInterface;?

import flash.utils.Timer;

import flash.events.TimerEvent;

OK, I added the following class import to the .as file:

import flash.events.MouseEvent;

THe line I mentioned earlier would (should) cover all events, but you're over that hump it appears.?The new error is telling you that the button (ssbpurchasetickets_btn) either doesn't have the instance name the code uses, or the button is not in the presence of the code when the code is processed.... meaning it might be somewhere down a timeline.

Mate, I'm having a hard time figuring this out - what does ''meaning it might be somewhere down a timeline'' mean?

The errors that follow this error are now - does this help?:

Warning: 3590: void used where a Boolean value was expected.?The expression will be type coerced to Boolean.

Warning: 3590: void used where a Boolean value was expected.?The expression will be type coerced to Boolean.

Warning: 3590: void used where a Boolean value was expected.?The expression will be type coerced to Boolean.

''either doesn't have the instance name the code uses...''

Have triple checked this and even copied the instance name and pasted it into the script so am pretty sure this is correct.

''or the button is not in the presence of the code when the code is processed...''

This sounds like the issue but am not sure of the cause. I pasted the script to a later frame incase the button needed time to appear?

''meaning it might be somewhere down a timeline...''

I'm not sure what is meant by ''down a timeline''.

I selected the text in the timeline, converted it to a button and gave it an instance name which I reference in the script. However, the timeline that contains all the animation (and my new button and Actionscript) is separate from the main timeline which just has a few frames in it - is this possibly the cause?

Those boolean error messages most likely indicate you have some functions that are returning boolean values but you have '':void'' specified as the return type.?Specifying :Boolean instead should fix that.

As far as the button goes, and down the timeline, it's all pretty much the same case of the button having to exist where the code is called upon.?If that button is somewhere down a timeline, like on frame 10, but the code is executing in frame 1, the button doesn't exist where the code is.

''Specifying :Boolean instead should fix that''

Specifying :Boolean has thrown up an additional error and the other ones still exist:

1170: Function does not return a value.

''If that button is somewhere down a timeline, like on frame 10, but the code is executing in frame 1, the button doesn't exist where the code is.''

Gotcha. The button first appears on frame 50 and the script is located on frame 80 - the last frame. Would it be fair to say the button is not in the presence of the script for some other reason?

BTW, this forums is bit weird, I click ''helpful answer'' and it states ''correct answer'' and when I submit replies, half my post disappears...

Have looked into classes and added the following to the .as file:

public function Home() {

Debugger.init(stage);

addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);

ssbpurchasetickets_btn.addEventListener(MouseEvent.CLICK, ssbButtonPurchase);

function ssbButtonPurchase(event:MouseEvent):void

{

navigateToURL(new URLRequest(''http://www.url.com/tickets.html''));

}

}

Not sure if I did this correctly but I got the exact same errors...

''Debugger.init(stage);

addEventListener(Event.ADDED_TO_STAGE, handleAddedToStage);''

Was already in the .as file.

Just to confirm things are setup correctly with the symbols:

- I have a button called: ssbpurchasetickets_btn

- In the timeline, that button has an instance name of: ssbpurchasetickets_btn

- My script calls ssbpurchasetickets_btn:

ssbpurchasetickets_btn.addEventListener(MouseEvent.CLICK, ssbButtonPurchase);

function ssbButtonPurchase(event:MouseEvent):void

{

navigateToURL(new URLRequest(''http://www.url.com/tickets.html''));

}

Frame 50 versus 80.?Here's another thing (a quirk in my opinion)... if the button transitions in, meaning at frame 50 it starts appearing or something and it finishes at frame 80, then you need to assign the instance name at all keyframes.?For whatever reason, if you have an object on successive keyframes and it does not have an instance name assigned in the first frame, that lack of an instance name is inherited by the instance in the next frame, regardless if it was assigned one in that second frame.

As for the boolean deal, change things back and live with the warnings for now.?I don't know what that is all about without see the functions in question... and the functions in question would have a libne in them that say: return something; // where something would have a true or false value?If no functions have that, then my diagnosis is wrong and I don't have any other idea what the warning is about.

''if the button transitions in''

Thanks mate, I was just reading about this in another forum post and the button does indeed transition in. I put the instance name on both the start and end keyframes and have checked that when the script is called on frame 80, that the button has that instance name - which it does.

Unfortunately I get the same error:

Description: 1120: Access of undefined property ssbpurchasetickets_btn.
Source: ssbpurchasetickets_btn.addEventListener(MouseEvent.CLICK, ssbButtonPurchase);

''As for the boolean deal, change things back and live with the warnings for now''

Have you enable to allow debugging option in the publish settings??Usually error messages will point to a frame/line number with that option selected.

I was going to mention.?AS3 errors can come in waves, meaning once you tackle one set of them, and think you're good as gold, another set that was waiting in the wings can step up for its turn... not all error message are displayed at once. I think it may stop at some point in compilation and say to itself ''that's enough for the moment''

Thanks Ned,

I did enable the extra debugging but I couldn't see any extra info. The only thing I haven't posted from the error is the location info:

Symbol 'container', Layer 'Layer 79', Frame 85, Line 2

Layer 79 is the actions layer, frame 85 is the last frame of the timeline that contains the action and line 2 is:

ssbpurchasetickets_btn.addEventListener(MouseEvent.CLICK, ssbButtonPurchase);

Line 1 is: stop();

I'm sure I'm missing something simple!

No comments:

Post a Comment