On 11/03/2010 12:37, Susan Day wrote:
On Thu, Mar 11, 2010 at 8:01 AM, Paul Andrews<p...@ipauland.com>  wrote:
Susan,

I think your main confusion lies with the concept of "attaching" code and
your "clarification" points to the URL being the content of the text field.

The natural place for your code is in the click handler.

The click handler knows which MC is involved, so it should be easily
possible to access the URL text via the event property passed to the click
handler.

Something like event.currentTarget.urlTextField.text

so in the click handler you need something like:

var pageURL:String = event.currentTarget.textField.text;

Then you can navigate. I'm not sure what you mean by "attach".

So I added a new child (in addition to TF) to the MC specifically to handle
the URL. I gave this new child a text property of the URL that is passed
through to the function. Now:
1) When I trace the value of this URL within the function in which the child
is created and added to the MC, the correct value traces.
2) When I explicitly add the correct value (as opposed to passing it as a
parameter to said function, which again printed correctly on trace), the
correct value is passed and the link is indeed established in the
onMouseClick function. Of course, that won't work on automatic generation,
since that same value will be passed to all instances, which is contrary to
what I need.
3) **However**, when I call the property in the onMouseClick function when
the URL is passed through to the initial function, onMouseClick truncates
".html"!!! The inelegant solution to this, of course, is to tag ".html" on
to that which is passed to the navigation function in the onMouseClick
function. Yuck. But hey, it works. Now the property which I use to attach
the URL to the newly created child is "text". If I use "htmlText", ugly
things happen (spits out all sorts of superfluous code).

OK, so it works. It's ugly, Any ideas on how to clean it up?

I think another poster has supplied a more elegant solution. In truth your code becomes complicated as you seek to a void using classes.

A simple class solution would be to extend MovieClip (or Sprite) and add a url string. This would allow you to stop messing about with children.

package {
            import flash.display.Sprite;
            public class URLClip extends Sprite{
                public var url:String;
                public function URLClip (){
                    // add your text fields here
                }
            }
}

Now you can set the url directly and access it later.

var newBtn:URLClip = new URLClip();
newBtn.url="http://goggle.com/";;


newBtn.addEventListener(MouseEvent.CLICK, onClick);

function onClick(e:Event):void{
        trace("navigate to "+e.currentTarget.url);
}

or something like that.


Paul



TIA,
Susan
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to