Asthma Relief & Management Serevent 25mcg Inhaler (Generic) $39.00

ActionScript 2.0

Asthma relief & management serevent 25mcg inhaler (generic) $39.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, asthma relief & management serevent 25mcg inhaler (generic) $39.00 <a> (anchor) tags are among the supported few, asthma relief & management serevent 25mcg inhaler (generic) $39.00 which means you can even put working hyperlinks inside your text.  Not only that, asthma relief & management serevent 25mcg inhaler (generic) $39.00 but Flash includes a special protocol, asthma relief & management serevent 25mcg inhaler (generic) $39.00 asfunction, asthma relief & management serevent 25mcg inhaler (generic) $39.00 that allows you to trigger functions from those hyperlinks, asthma relief & management serevent 25mcg inhaler (generic) $39.00 in case you prefer to do that instead of visiting URLs.  ActionScript 3.0 uses a different approach, asthma relief & management serevent 25mcg inhaler (generic) $39.00 but if you’re coding in AS1 or 2, asthma relief & management serevent 25mcg inhaler (generic) $39.00 just replace http://someURL.com with asfunction:someFunction, asthma relief & management serevent 25mcg inhaler (generic) $39.00someParam, asthma relief & management serevent 25mcg inhaler (generic) $39.00 as described elsewhere on this blog.  If you’re coding in timeline keyframes, asthma relief & management serevent 25mcg inhaler (generic) $39.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

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 When a text field responds to an asfunction trigger, asthma relief & management serevent 25mcg inhaler (generic) $39.00 it looks for the specified function inside the movie clip that contains the text field in question (that is, asthma relief & management serevent 25mcg inhaler (generic) $39.00 the container object of that text field, asthma relief & management serevent 25mcg inhaler (generic) $39.00 or its parent).  Again, asthma relief & management serevent 25mcg inhaler (generic) $39.00 if you’re coding on the timeline, asthma relief & management serevent 25mcg inhaler (generic) $39.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, asthma relief & management serevent 25mcg inhaler (generic) $39.00param'>click me</a>";

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 When a user clicks the words “click me” in this text field, asthma relief & management serevent 25mcg inhaler (generic) $39.00 asfunction looks for a function named linkHandler() in the movie clip (aka the timeline) that contains this text field.  And of course, asthma relief & management serevent 25mcg inhaler (generic) $39.00 there it is, asthma relief & management serevent 25mcg inhaler (generic) $39.00 in the very same keyframe.

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 In some custom class situations, asthma relief & management serevent 25mcg inhaler (generic) $39.00 the above concept still works without a hitch.  If your class extends MovieClip, asthma relief & management serevent 25mcg inhaler (generic) $39.00 for example, asthma relief & management serevent 25mcg inhaler (generic) $39.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", asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 100, asthma relief & management serevent 25mcg inhaler (generic) $39.00 22);
    tf.html = true;
    tf.htmlText = "<a href='asfunction:linkHandler, asthma relief & management serevent 25mcg inhaler (generic) $39.00clicked'>click me</a>";
  }
  private function linkHandler(param:String):Void {
    trace(param);
  }
}

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 In the preceding code, asthma relief & management serevent 25mcg inhaler (generic) $39.00 an arbitrarily named property, asthma relief & management serevent 25mcg inhaler (generic) $39.00 tf, asthma relief & management serevent 25mcg inhaler (generic) $39.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., asthma relief & management serevent 25mcg inhaler (generic) $39.00 it is a movie clip).  In the following line, asthma relief & management serevent 25mcg inhaler (generic) $39.00 tf’s TextField.html property is set to true, asthma relief & management serevent 25mcg inhaler (generic) $39.00 which allows it to accept HTML input, asthma relief & management serevent 25mcg inhaler (generic) $39.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, asthma relief & management serevent 25mcg inhaler (generic) $39.00 this time passing in the parameter “clicked” (a string).  The private linkHandler() method (which could be public too, asthma relief & management serevent 25mcg inhaler (generic) $39.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.

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 Note:  To test the above class, asthma relief & management serevent 25mcg inhaler (generic) $39.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, asthma relief & management serevent 25mcg inhaler (generic) $39.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?

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 The problem is, asthma relief & management serevent 25mcg inhaler (generic) $39.00 your class might not extend MovieClip (or extend anything!) at all.  Which would be fine.  There’s no reason to extend MovieClip, asthma relief & management serevent 25mcg inhaler (generic) $39.00 or any class, asthma relief & management serevent 25mcg inhaler (generic) $39.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", asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 100, asthma relief & management serevent 25mcg inhaler (generic) $39.00 22);
    tf.html = true;
    tf.htmlText = "<a href='asfunction:linkHandler, asthma relief & management serevent 25mcg inhaler (generic) $39.00clicked'>click me</a>";
  }
  private function linkHandler(param:String):Void {
    trace(param);
  }
}

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 What’s the difference?  This time, asthma relief & management serevent 25mcg inhaler (generic) $39.00 the class doesn’t extend anything.  It’s instantiated in the main timeline …

new CustomClass(this);

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 … and fed a MovieClip instance — here, asthma relief & management serevent 25mcg inhaler (generic) $39.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, asthma relief & management serevent 25mcg inhaler (generic) $39.00 but when this class is instantiated, asthma relief & management serevent 25mcg inhaler (generic) $39.00 the text field becomes an immediate child of the main timeline.  The problem is, asthma relief & management serevent 25mcg inhaler (generic) $39.00 the class itself — which contains the linkHandler() method — is also a child of the main timeline, asthma relief & management serevent 25mcg inhaler (generic) $39.00 which means asfunction is looking in the wrong place for linkHandler().  As always, asthma relief & management serevent 25mcg inhaler (generic) $39.00 asfunction is looking in the movie clip that contains the text field.  Here, asthma relief & management serevent 25mcg inhaler (generic) $39.00 the movie clip is the main timeline, asthma relief & management serevent 25mcg inhaler (generic) $39.00 but the desired function is inside an object (this CustomClass instance) inside the main timeline.  So close, asthma relief & management serevent 25mcg inhaler (generic) $39.00 but yet so far, asthma relief & management serevent 25mcg inhaler (generic) $39.00 eh?

So what’s a solution?

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 The easiest way to fix the disconnect is to re-route the function, asthma relief & management serevent 25mcg inhaler (generic) $39.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", asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 100, asthma relief & management serevent 25mcg inhaler (generic) $39.00 22);
  tf.html = true;
  tf.htmlText = "<a href='asfunction:linkHandler, asthma relief & management serevent 25mcg inhaler (generic) $39.00clicked'>click me</a>";
  tf._parent.linkHandler = this.linkHandler;
}

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 The workaround here takes advantage of the fact that the MovieClip class is dynamic, asthma relief & management serevent 25mcg inhaler (generic) $39.00 which means it can have properties and methods added to it at runtime.  In this case, asthma relief & management serevent 25mcg inhaler (generic) $39.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, asthma relief & management serevent 25mcg inhaler (generic) $39.00 you could also use the following in this scenario, asthma relief & management serevent 25mcg inhaler (generic) $39.00 which means the exact same thing:

target.linkHandler = this.linkHandler;

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 It’s interesting to note that linkHandler(), asthma relief & management serevent 25mcg inhaler (generic) $39.00 as defined in the class, asthma relief & management serevent 25mcg inhaler (generic) $39.00 is private, asthma relief & management serevent 25mcg inhaler (generic) $39.00 yet the twin function, asthma relief & management serevent 25mcg inhaler (generic) $39.00 dynamically set to a different MovieClip instance, asthma relief & management serevent 25mcg inhaler (generic) $39.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, asthma relief & management serevent 25mcg inhaler (generic) $39.00 but hey, asthma relief & management serevent 25mcg inhaler (generic) $39.00 you’re a developer.  That makes you like a stage hand.  You keep the magician’s secrets.

Is there a better solution?

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 There is a better solution — though “better” is subjective, asthma relief & management serevent 25mcg inhaler (generic) $39.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, asthma relief & management serevent 25mcg inhaler (generic) $39.00 if you replace trace(param); with trace(this);, asthma relief & management serevent 25mcg inhaler (generic) $39.00 you’ll see _level0 in the Output panel.  Why?  Because the dynamically added function exists in the main timeline, asthma relief & management serevent 25mcg inhaler (generic) $39.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, asthma relief & management serevent 25mcg inhaler (generic) $39.00 however, asthma relief & management serevent 25mcg inhaler (generic) $39.00 is that this refers to an object that isn’t the CustomClass instance.)

Asthma relief & management serevent 25mcg inhaler (generic) $39.00 To re-route not only the function, asthma relief & management serevent 25mcg inhaler (generic) $39.00 but its scope, asthma relief & management serevent 25mcg inhaler (generic) $39.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", asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 0, asthma relief & management serevent 25mcg inhaler (generic) $39.00 100, asthma relief & management serevent 25mcg inhaler (generic) $39.00 22);
    tf.html = true;
    tf.htmlText = "<a href='asfunction:linkHandler, asthma relief & management serevent 25mcg inhaler (generic) $39.00clicked'>click me</a>";
    tf._parent.linkHandler = Delegate.create(this, asthma relief & management serevent 25mcg inhaler (generic) $39.00 linkHandler);
  }
  private function linkHandler(param:String):Void {
    trace(param);
  }
}

Average Rating: 4.6 out of 5 based on 155 user reviews.

Leave a Reply