PDA

View Full Version : Can't get button to load html into frame..



statikcat
June 26th, 2007, 11:57 AM
This is very frustrating. I am working on a new site in CS3 and have used previous versions of Flash with little issues. CS3 and AS3 just seems convoluted .. like I am learning the app all over again!

First of all.. it seems you don't add actionscript to buttons anymore.. but actual frames. Ok.. well what if you have more than one button on a frame? How do you designate actionscript on a frame to a certain button? I would guess something with the button ID/instance name?

All I really want to know is what code to assign a button to load a .html file into a lower frame. This seems SO SIMPLE yet all of the AS3 code I have found online and in the CS3 help menu give me errors and when I play my flash file it just goes on repeat forever.

Can someone please shed some light on this? Flash was easy before now I feel like I need to be a computer programmer.

statikcat
June 26th, 2007, 12:40 PM
Update:

Ok I found this code on Adobe site:

var url = "bottom2.html";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request);
}
catch (e:Error) {
// Handle error...
}

As of right now I just have this on a frame and when that frame is played it loads the bottom.html.

But how do I assign this command to a button and tell it to load in a certain frame? I am somewhat on the right track but still lost when it comes to the above.

I basically have a top and bottom frame. The top frame is flash menu that simply loads html files into the bottom frame via buttons. This should be simple! Hopefully it is! =-D

dthought
June 26th, 2007, 11:14 PM
Yes, AS2.0 to AS3.0 is a lot of relearning. You are going to have to learn a lot more about being a programmer-type person than you have in the past if you pursue knowledge of AS3.0.

The following example is hard-coded, as I'm still learning too and have been scratching my head about somehow storing the URL and target window data on the button itself... but as buttons are not dynamic, Flash gets very unhappy. Not sure of the best way to deal with this, yet.

This example assumes the existence of a button on the stage with instance name "myButton".



function openFramePage (evt:MouseEvent):void
{
var theURL:String = 'bottom2.html';
var targetWindow:String = '_self';
var theRequest:URLRequest = new URLRequest(theURL);

try
{
navigateToURL(theRequest, targetWindow);
}
catch (err:Error)
{
// Handle error...
trace ('Something bad happened');
}
}

myButton.addEventListener(MouseEvent.CLICK, openFramePage, false, 0, true);

statikcat
June 27th, 2007, 12:59 AM
Thanks I will give that a try in the morning. I would like to stick with Flash 8 for now but being on an Intel Mac CS3 works a lot better. I may just have to put ver 8 on here for the time being as well. I would like to learn CS3 though and this seems like good help and thanks for the reply.

dthought
June 27th, 2007, 02:37 AM
Just change your Publish Settings to ActionScript 2.0 to have it behave the "older" way...

statikcat
June 27th, 2007, 10:08 AM
Oh nice thanks Dthought that will be very helpful. See I tried changing to AS2 in the actionscripts window .. but of course AS2 code will not work for buttons since it still needs to be put on a frame.

However, now when I change to AS2 in publish settings it lets me put the code on the button itself. Thanks very much!

statikcat
June 29th, 2007, 11:28 AM
The Flash 8 way of loading buttons to frames doesnt work in CS3!

http://www.kirupa.com/developer/flash5/frames.htm

That simply does not work in CS3. I followed instructions exactly. Does not work on this example or in my own. My HTML target frame and flash "window" are the same name and yet it refusess to load. In publish settings I have Flash 8 / AS2 selected. I have also tried Flash 5, etc publish settings.

Any ideas? Is this a CS3 issue? I dont want to have to redesign the Flash menu in another version of flash from scratch..

dthought
July 1st, 2007, 12:37 AM
That ain't Flash 8 - that's Flash 5... very antiquated by Flash standards!

You have to choose which version of ActionScript you're going to use - AS1.0, 2.0 or 3.0. 1 and 2 are fairly close, but 3 is quite different.

If you have a mixture of all three, you're invariably going to run into problems.

The easiest way for you, if you're familiar with AS1.0 or 2.0, is to set your publish settings to AS2.0 - that means, do not use any AS3.0 specific code... so you'll be using things like _x, _y and onClipEvent instead of x, y and addEventListener.

If you're having AS2.0-specific issues, try asking your question in the AS2.0 forum :)

choreo
July 3rd, 2007, 09:09 PM
Boy, I wish I had read your thread first - I am up against the EXACT same problem. I just spent over a month building a site with Frames where the upper frame is a Flash AS3 navigation menu with about 50 buttons - each of which is designed to load a page into the bottom frame and it simply will not work. I have purchased and studied all the TotalTraining Actionscript 3 tutorials which say nothing about how to do this. I see nothing in the Flash CS3 Help files that even give a clue - NOT ONE SINGLE EXAMPLE!!! If this were something out of the ordinary I would understand, but this is a VERY COMMON use of Flash (creating Flash navigation in one stationary frame and using it to control the content in a second "dynamic" content frame). I see sites like this everyday like http://www.katzkin.com that do this, but apparently they have not tried this with AS3.0!!! (or they know a trick that I don't).

Now my problem is I have spent over a month designing a Flash Menu in AS3 and it looks like I am going to have to scrap it and start over using AS2.0 before I lose my client. I have everything working in AS 3 except I cannot write the code to make a button load a page into the a target frame within my frameset.

I HAVE been able to click a button in the Flash Nav Menu in my top frame and have it open the linked page in a NEW browser window (just like specifying "_blank"), but that does me no good. I have scoured the Internet and the Flash Forums - apparently nobody can do this yet in AS3. VERY FRUSTRATING!

Here is the code I have on a button right now, but it ignores my frame target and just opens in a new window.

function loadPageFrame(event:MouseEvent):void
{
var myURL:URLRequest = new URLRequest("CorporateOverview.html");
navigateToURL(myURL,"mainFrame");
}
Btn1.addEventListener(MouseEvent.CLICK, loadPageFrame);

If you have any new info it would be MUCH APPRECIATED!

call(911)
August 2nd, 2007, 02:04 PM
Here is some 3.0 as that provides communication between the two .swf's.


To do this, you will create two .fla's. One of them you'll call outgoing, the other one incoming - then follow the instructions below:



outgoing.fla

- create a movie clip and call it whatever you like, but give it an instance name of send_btn

- Inside your movie clip, put an input text box and give it the instance name of userMessage_txt

- leave the mc/text box on stage, and on the first frame put this as code...

import flash.events.MouseEvent;
import flash.net.LocalConnection;
var outgoing_lc:LocalConnection = new LocalConnection();
function clickSend(event:MouseEvent):void
{
outgoing_lc.send("lc_example", "methodToExecute", userMessage_txt.text);
}
send_btn.addEventListener(MouseEvent.CLICK, clickSend);

----------------------------------

incoming.fla

- create a dynamic text field and give it an instance name of sentMessage_txt

All if the code needed in this .fla will be in the first frame:

import flash.net.LocalConnection;
var incoming_lc:LocalConnection = new LocalConnection();
incoming_lc.connect("lc_example");
function methodToExecute(param:String):void
{
sentMessage_txt.text = param;
}
incoming_lc.client = this;

----------------

publish both movies and run or embed in html.