开发者

Simple Flash form, redirecting to URL using textfield as argument

This seemed simple enough, I do know Java, PHP and JavaScript, so it's simply a matter of not e开发者_开发技巧nough knowledge of the Flash/ActionScript 3.0 platform.

After doing some research, I added a layer to the movie for the code (Flash CS5). I then right-click, select "Actions" and write this code.

addEventListener(Event.ENTER_FRAME, setup);

submitButton.addEventListener(MouseEvent.CLICK, onSubmit);
queryField.addEventListener(MouseEvent.CLICK, onQueryClick);

var defaultText = "Search...";

function setup(){
    queryField.text = defaultText;
}
function onSubmit(){
    if(queryField.text != defaultText && queryField.text != ""){
        navigateToURL(new URLRequest("http://www.somedomain.com/?query=" + queryField.text), "_blank");
    }
}
function onQueryClick(){ 
    if(queryField.text == defaultText){
        queryField.text = "";
    }
}

As you can see, I want to add a default text on load to the form field referenced by "queryField", which should clear on focusing the field. When submitting the form the browser should redirect to an URL appending the value of queryField.

As I said, I don't have enough knowledge of the platform to know what's wrong. Although it seems like maybe the references in the functions are not available due to the different scope. But a different example I saw ignored scope of form field references as well.

Right now, the published movies does precisely nothing.


In order to set a default value to the TextField, there is no need to use an ENTER_FRAME event. Just do that :

var defaultText = "Search...";
queryField.text = defaultText;

In your code, the TextField is continously updated with the default value (see the ENTER_FRAME event documentation). That's why nothing happend, the TextField is always equal to the default text.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜