2 Replies Latest reply on Oct 5, 2006 10:08 AM by YossarianXOS

    Help with Including AS Files

    YossarianXOS
      Probably a ridiculously simple question here, but I'm trying to include a 3rd party package (really simple marquee script) into my flex project, but the compiler keeps throwing out a 1037 error on me, and I'm lost as to what I'm doing wrong.

      quote:


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      ....
      >
      <mx:Script source="Marquee.as"/>

      <mx:Style source="layout_red.css"/>

      ....
      ....

      <Marquee text="This is a test marquee to display the behavior" direction="both" width="100" />



      And then I have the Marquee.as file in the same directory, and it looks like this:

      quote:


      package {

      import mx.controls.Label;
      import flash.utils.Timer;
      import flash.events.TimerEvent;

      public class Marquee extends Label
      {

      public function Marquee()
      {
      super();
      timer = new Timer(100);
      timer.addEventListener(TimerEvent.TIMER, timeUpdate);
      timer.start();
      super.truncateToFit = false;
      }

      public var direction:String="left";
      public var speed:int=4;

      private var __text:String = "";
      private var __dtext:String = "";
      private var position:int = 0;
      private var _direction:int = 1;
      private var timer:Timer;

      override public function get text():String
      {
      return __text;
      }

      override public function set text(newText:String):void
      {
      __text = newText;
      __dtext = newText + " " + newText;
      if (direction == "both")
      super.text = __text;
      else
      super.text = __dtext;

      }

      public function get delay():int
      {
      return timer.delay;
      }

      public function set delay(newDelay:int):void
      {
      timer.delay = newDelay;
      }

      private function timeUpdate(event:TimerEvent):void
      {
      switch(direction)
      {
      case "right":
      {
      if (position <= 0)
      position = textField.maxScrollH;
      else
      position -= speed;
      break;
      }

      case "left":
      {
      if (position >= textField.maxScrollH)
      position = 0;
      else
      position += speed;
      break;
      }

      case "both":
      {
      position += _direction*speed;
      if (position <= 0 || position >= textField.maxScrollH)
      _direction = -_direction;
      if (super.text != __text)
      super.text = __text;
      break;
      }
      }
      textField.scrollH = position;
      }
      }
      }



      Could someone point me in the right direction with this, please?
        • 1. Re: Help with Including AS Files
          nated
          Here's an idea:
          In your <mx:Application> tag - after xmlns:mx=" http://www.adobe.com/2006/mxml", add xmlns:myComponents="myComponents.Marquee"

          Then, in your file structure, add a folder "myComponents". Inside that folder, add the Marquee.as file.
          If you can edit the Marquee.as file, change the very first line to "package myComponents {". I don't know for sure if you need to change that line, but I know it would fix your issue! :D
          • 2. Re: Help with Including AS Files
            YossarianXOS Level 1
            Thanks a ton Nated!

            One minor correction before it worked though...

            I had to put in:

            quote:

            xmlns:myComponents="myComponents.*"


            That way I was able to call the Marquee function like this:

            quote:

            <myComponents:Marquee .... />


            Without the wildcard character it wasn't able to find the Marquee function for some reason. Otherwise though, that's exactly what I needed.