Risperdal 3mg Pills $126.00

ActionScript 2.0

Risperdal 3mg pills $126.00 Flash Player has supported a limited subset of the HTML specification since version 6 — just set a text field’s htmlText property to an HTML-formatted string and you’re good to go.  Fortunately, risperdal 3mg pills $126.00 <a> (anchor) tags are among the supported few, risperdal 3mg pills $126.00 which means you can even put working hyperlinks inside your text.  Not only that, risperdal 3mg pills $126.00 but Flash includes a special protocol, risperdal 3mg pills $126.00 asfunction, risperdal 3mg pills $126.00 that allows you to trigger functions from those hyperlinks, risperdal 3mg pills $126.00 in case you prefer to do that instead of visiting URLs.  ActionScript 3.0 uses a different approach, risperdal 3mg pills $126.00 but if you’re coding in AS1 or 2, risperdal 3mg pills $126.00 just replace http://someURL.com with asfunction:someFunction, risperdal 3mg pills $126.00someParam, risperdal 3mg pills $126.00 as described elsewhere on this blog.  If you’re coding in timeline keyframes, risperdal 3mg pills $126.00 it’s all pretty straightforward.  But asfunction can seemingly break when used in custom class files.  Here’s what’s going on and how to fix it. 

A bit of backstory

Risperdal 3mg pills $126.00 When a text field responds to an asfunction trigger, risperdal 3mg pills $126.00 it looks for the specified function inside the movie clip that contains the text field in question (that is, risperdal 3mg pills $126.00 the container object of that text field, risperdal 3mg pills $126.00 or its parent).  Again, risperdal 3mg pills $126.00 if you’re coding on the timeline, risperdal 3mg pills $126.00 everything tends to fall into place.  Imagine the following ActionScript 2.0 in a keyframe of the main timeline:

function linkHandler(param:String):Void {
  // do something neat with the hyperlink
}

myTextField.htmlText = "<a href='asfunction:linkHandler, risperdal 3mg pills $126.00param'>click me</a>";

Risperdal 3mg pills $126.00 When a user clicks the words “click me” in this text field, risperdal 3mg pills $126.00 asfunction looks for a function named linkHandler() in the movie clip (aka the timeline) that contains this text field.  And of course, risperdal 3mg pills $126.00 there it is, risperdal 3mg pills $126.00 in the very same keyframe.

Risperdal 3mg pills $126.00 In some custom class situations, risperdal 3mg pills $126.00 the above concept still works without a hitch.  If your class extends MovieClip, risperdal 3mg pills $126.00 for example, risperdal 3mg pills $126.00 then the class itself becomes the “timeline” that contains both the text field and asfunction’s function.

class CustomClass extends MovieClip {
  private var tf:TextField;
  public function CustomClass() {
    tf = this.createTextField("tf", risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 100, risperdal 3mg pills $126.00 22);
    tf.html = true;
    tf.htmlText = "<a href='asfunction:linkHandler, risperdal 3mg pills $126.00clicked'>click me</a>";
  }
  private function linkHandler(param:String):Void {
    trace(param);
  }
}

Risperdal 3mg pills $126.00 In the preceding code, risperdal 3mg pills $126.00 an arbitrarily named property, risperdal 3mg pills $126.00 tf, risperdal 3mg pills $126.00 is declared and — inside the constructor function — set to an instance of the TextField class by way of the MovieClip.createTextField() method.  This method succeeds here when invoked on the global this property because the class extends MovieClip (i.e., risperdal 3mg pills $126.00 it is a movie clip).  In the following line, risperdal 3mg pills $126.00 tf’s TextField.html property is set to true, risperdal 3mg pills $126.00 which allows it to accept HTML input, risperdal 3mg pills $126.00 then its htmlText property is set to the same HTML-formatted string as before.  Note that asfunction still points to a custom linkHandler() function, risperdal 3mg pills $126.00 this time passing in the parameter “clicked” (a string).  The private linkHandler() method (which could be public too, risperdal 3mg pills $126.00 either way) hears asfunction’s call when the hyperlink is clicked.  All is still well — the Output panel traces the word “clicked” because param’s value is that word.

Risperdal 3mg pills $126.00 Note:  To test the above class, risperdal 3mg pills $126.00 you’ll have to save the preceding code as a simple text file named CustomClass.as and put it into the same folder as a new FLA.  Inside that FLA, risperdal 3mg pills $126.00 draw a quick rectangle and convert it to a movie clip symbol.  Right-click / Command-click the symbol in the Library and choose Linkage from the context menu.  Check “Export for ActionScript” and type the name of the class (CustomClass) into the Class field.

So what’s the problem?

Risperdal 3mg pills $126.00 The problem is, risperdal 3mg pills $126.00 your class might not extend MovieClip (or extend anything!) at all.  Which would be fine.  There’s no reason to extend MovieClip, risperdal 3mg pills $126.00 or any class, risperdal 3mg pills $126.00 unless the class you’re writing actually is an example of the class you’re extending.  In the following code — almost identical — asfunction is no longer able to find its linkHandler() function:

class CustomClass {
  private var tf:TextField;
  public function CustomClass(target:MovieClip) {
    tf = target.createTextField("tf", risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 100, risperdal 3mg pills $126.00 22);
    tf.html = true;
    tf.htmlText = "<a href='asfunction:linkHandler, risperdal 3mg pills $126.00clicked'>click me</a>";
  }
  private function linkHandler(param:String):Void {
    trace(param);
  }
}

Risperdal 3mg pills $126.00 What’s the difference?  This time, risperdal 3mg pills $126.00 the class doesn’t extend anything.  It’s instantiated in the main timeline …

new CustomClass(this);

Risperdal 3mg pills $126.00 … and fed a MovieClip instance — here, risperdal 3mg pills $126.00 the global this property — as a parameter.  The only reason for the parameter is so that the target reference inside the constructor function can be used in the very next line as the MovieClip instance required for the createTextField() method.  The difference may be subtle, risperdal 3mg pills $126.00 but when this class is instantiated, risperdal 3mg pills $126.00 the text field becomes an immediate child of the main timeline.  The problem is, risperdal 3mg pills $126.00 the class itself — which contains the linkHandler() method — is also a child of the main timeline, risperdal 3mg pills $126.00 which means asfunction is looking in the wrong place for linkHandler().  As always, risperdal 3mg pills $126.00 asfunction is looking in the movie clip that contains the text field.  Here, risperdal 3mg pills $126.00 the movie clip is the main timeline, risperdal 3mg pills $126.00 but the desired function is inside an object (this CustomClass instance) inside the main timeline.  So close, risperdal 3mg pills $126.00 but yet so far, risperdal 3mg pills $126.00 eh?

So what’s a solution?

Risperdal 3mg pills $126.00 The easiest way to fix the disconnect is to re-route the function, risperdal 3mg pills $126.00 which can be done with a single line.  Here’s a quick look at the constructor function only:

public function CustomClass(target:MovieClip) {
  tf = target.createTextField("tf", risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 100, risperdal 3mg pills $126.00 22);
  tf.html = true;
  tf.htmlText = "<a href='asfunction:linkHandler, risperdal 3mg pills $126.00clicked'>click me</a>";
  tf._parent.linkHandler = this.linkHandler;
}

Risperdal 3mg pills $126.00 The workaround here takes advantage of the fact that the MovieClip class is dynamic, risperdal 3mg pills $126.00 which means it can have properties and methods added to it at runtime.  In this case, risperdal 3mg pills $126.00 a reference is made to the movie clip that contains the text field — tf._parent (the TextField._parent property of tf) — and then a new function is declared in that movie clip and set to the function defined inside the class.  Because the constructor function accepts a target parameter, risperdal 3mg pills $126.00 you could also use the following in this scenario, risperdal 3mg pills $126.00 which means the exact same thing:

target.linkHandler = this.linkHandler;

Risperdal 3mg pills $126.00 It’s interesting to note that linkHandler(), risperdal 3mg pills $126.00 as defined in the class, risperdal 3mg pills $126.00 is private, risperdal 3mg pills $126.00 yet the twin function, risperdal 3mg pills $126.00 dynamically set to a different MovieClip instance, risperdal 3mg pills $126.00 is able to invoke this private method without any issues.  That’s just the broken way it works in AS2.  It shouldn’t do that, risperdal 3mg pills $126.00 but hey, risperdal 3mg pills $126.00 you’re a developer.  That makes you like a stage hand.  You keep the magician’s secrets.

Is there a better solution?

Risperdal 3mg pills $126.00 There is a better solution — though “better” is subjective, risperdal 3mg pills $126.00 and you really only need the alternate approach if the scope of your function needs to reside inside the class.  Under the current setup, risperdal 3mg pills $126.00 if you replace trace(param); with trace(this);, risperdal 3mg pills $126.00 you’ll see _level0 in the Output panel.  Why?  Because the dynamically added function exists in the main timeline, risperdal 3mg pills $126.00 so the this reference thinks that’s where it is.  (It only happens like this because the parent of the text field happens to be the main timeline.  The point, risperdal 3mg pills $126.00 however, risperdal 3mg pills $126.00 is that this refers to an object that isn’t the CustomClass instance.)

Risperdal 3mg pills $126.00 To re-route not only the function, risperdal 3mg pills $126.00 but its scope, risperdal 3mg pills $126.00 use the Delegate class as follows:

import mx.utils.Delegate;
class CustomClass {
  private var tf:TextField;
  public function CustomClass(target:MovieClip) {
    tf = target.createTextField("tf", risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 0, risperdal 3mg pills $126.00 100, risperdal 3mg pills $126.00 22);
    tf.html = true;
    tf.htmlText = "<a href='asfunction:linkHandler, risperdal 3mg pills $126.00clicked'>click me</a>";
    tf._parent.linkHandler = Delegate.create(this, risperdal 3mg pills $126.00 linkHandler);
  }
  private function linkHandler(param:String):Void {
    trace(param);
  }
}

Average Rating: 4.8 out of 5 based on 168 user reviews.

Leave a Reply