Flash tooltip text styling question

  • environmentflash
  • Newbie
  • Newbie
  • environmentflash
  • Posts: 7

Post 3+ Months Ago

Hi,

I have inherited a Flash virtual tour from a previous colleague and have hit a snag. The tool tip I am using draws on the "alt" tag from my xml document. I need to make the scientific names italic but can't seem to make just a few words italic.

In the xml document I can specify the altFont and make the whole line italic...but really need to just specify a few words in the sentence.

I was thinking maybe I need to add something to the Flash actionscript and specify a new "attribute"? I am a designer and not a developer so hope there is someone out there who could point me in the right direction?

Below is the actionscript...

Thanks heaps!

ACTIONSCRIPT Code: [ Select ]
// Tooltips plugin
 
var id:String="Tootips";
var version:String="1.0";
var panoController:Object=null;
var pano:Object=null;
var hotspots:Object;
var waitTimer:Timer;
 
// this function is called on plugin's start
function init (panoMain:Object) {
   panoController = panoMain;
   if (panoMain.addExternal(this)) {
      waitTimer = new Timer(50);
      waitTimer.addEventListener(TimerEvent.TIMER, waitHotspots, false, 0, true);
      waitTimer.start();
   }     
}
 
// this function is called when new panorama is loading
function newPano(link:Object) {
   pano = link;
}
 
// wait for Hotspots plugin to load before starting tooltips
function waitHotspots (event:Event) {
   if (panoController.externals.hotspots!=null) {
      waitTimer.stop();
      waitTimer = null
      hotspots = panoController.externals.hotspots;
      hotspots.addEventListener(MouseEvent.MOUSE_OVER, doOver, false, 0, true);
      hotspots.addEventListener(MouseEvent.MOUSE_OUT, doOut, false, 0, true);
      hotspots.addEventListener(MouseEvent.CLICK, doOut, false, 0, true);
   }
}
 
var animationTimer:Timer;
var speed:Number;
var currentObject:Object;
var alphaMax:Number = 1;
var alphaMin:Number = -1.4;
var alphaPlus:Number = 0.2;
var alphaMinus:Number = -0.08;
 
visible = false;
alpha = alphaMin;
tip.scale9Grid = new Rectangle(5, 5, tip.width-10, tip.height-10);
tip_txt.autoSize = TextFieldAutoSize.LEFT;
 
function doOver (event:Event) {
   // find object with property "attributes" (all hotspots has this object)
   var obj:Object = event.target;
   while (!obj.hasOwnProperty("attributes")) {
      if (obj.hasOwnProperty("parent")) {
         obj = obj.parent;
      } else {
         return;
      }
   }
   // try to get propery alt (stored in XML: <spot url="1.jpg" alt="My Picture" />)
   var text:String = obj.attributes.getParam("alt");
   if (text!=null) {
      currentObject = obj;
      // if text contais \n, it is multilines
      if (text.indexOf("\\n")!=-1) {
         text = text.replace(/\\n/g, "\n")
      }
      tip_txt.text = text;
      tip.width = tip_txt.width+10;
      tip.height = tip_txt.height+4;
      // start animation
      speed = alphaPlus;
      visible = true;
      if (animationTimer!=null) {
         animationTimer.stop();
      }
      animationTimer = new Timer(30);
      animationTimer.addEventListener(TimerEvent.TIMER, animation, false, 0, true);
      animationTimer.start();
   }
}
 
function doOut (event:Event) {
   speed = alphaMinus;
}
 
function animation (event:Event) {
   if (speed>0) {
      if (alpha < alphaMax) {
         alpha += speed;
      } else {
         alpha = alphaMax;
      }
      x = parent.mouseX-8;
      y = parent.mouseY+20;
      //
      if (x<0) {
         x = 0;
      }
      if (x+width>pano.width) {
         x = pano.width-width;
      }
      if (y+height>pano.height) {
         y = pano.height-height;
      }
      if (!currentObject.visible) {
         speed = alphaMinus;
      }
   } else {
      if (alpha > alphaMin) {
         alpha += speed;
      } else {
         alpha = alphaMin;
         animationTimer.stop();
         animationTimer = null;
      }
   }
}
 
function remove () {
   hotspots.removeEventListener(MouseEvent.MOUSE_OVER, doOver);
   hotspots.removeEventListener(MouseEvent.MOUSE_OUT, doOut);
   if (animationTimer!=null) {
      animationTimer.stop();
   }
   animationTimer = null;
}
  1. // Tooltips plugin
  2.  
  3. var id:String="Tootips";
  4. var version:String="1.0";
  5. var panoController:Object=null;
  6. var pano:Object=null;
  7. var hotspots:Object;
  8. var waitTimer:Timer;
  9.  
  10. // this function is called on plugin's start
  11. function init (panoMain:Object) {
  12.    panoController = panoMain;
  13.    if (panoMain.addExternal(this)) {
  14.       waitTimer = new Timer(50);
  15.       waitTimer.addEventListener(TimerEvent.TIMER, waitHotspots, false, 0, true);
  16.       waitTimer.start();
  17.    }     
  18. }
  19.  
  20. // this function is called when new panorama is loading
  21. function newPano(link:Object) {
  22.    pano = link;
  23. }
  24.  
  25. // wait for Hotspots plugin to load before starting tooltips
  26. function waitHotspots (event:Event) {
  27.    if (panoController.externals.hotspots!=null) {
  28.       waitTimer.stop();
  29.       waitTimer = null
  30.       hotspots = panoController.externals.hotspots;
  31.       hotspots.addEventListener(MouseEvent.MOUSE_OVER, doOver, false, 0, true);
  32.       hotspots.addEventListener(MouseEvent.MOUSE_OUT, doOut, false, 0, true);
  33.       hotspots.addEventListener(MouseEvent.CLICK, doOut, false, 0, true);
  34.    }
  35. }
  36.  
  37. var animationTimer:Timer;
  38. var speed:Number;
  39. var currentObject:Object;
  40. var alphaMax:Number = 1;
  41. var alphaMin:Number = -1.4;
  42. var alphaPlus:Number = 0.2;
  43. var alphaMinus:Number = -0.08;
  44.  
  45. visible = false;
  46. alpha = alphaMin;
  47. tip.scale9Grid = new Rectangle(5, 5, tip.width-10, tip.height-10);
  48. tip_txt.autoSize = TextFieldAutoSize.LEFT;
  49.  
  50. function doOver (event:Event) {
  51.    // find object with property "attributes" (all hotspots has this object)
  52.    var obj:Object = event.target;
  53.    while (!obj.hasOwnProperty("attributes")) {
  54.       if (obj.hasOwnProperty("parent")) {
  55.          obj = obj.parent;
  56.       } else {
  57.          return;
  58.       }
  59.    }
  60.    // try to get propery alt (stored in XML: <spot url="1.jpg" alt="My Picture" />)
  61.    var text:String = obj.attributes.getParam("alt");
  62.    if (text!=null) {
  63.       currentObject = obj;
  64.       // if text contais \n, it is multilines
  65.       if (text.indexOf("\\n")!=-1) {
  66.          text = text.replace(/\\n/g, "\n")
  67.       }
  68.       tip_txt.text = text;
  69.       tip.width = tip_txt.width+10;
  70.       tip.height = tip_txt.height+4;
  71.       // start animation
  72.       speed = alphaPlus;
  73.       visible = true;
  74.       if (animationTimer!=null) {
  75.          animationTimer.stop();
  76.       }
  77.       animationTimer = new Timer(30);
  78.       animationTimer.addEventListener(TimerEvent.TIMER, animation, false, 0, true);
  79.       animationTimer.start();
  80.    }
  81. }
  82.  
  83. function doOut (event:Event) {
  84.    speed = alphaMinus;
  85. }
  86.  
  87. function animation (event:Event) {
  88.    if (speed>0) {
  89.       if (alpha < alphaMax) {
  90.          alpha += speed;
  91.       } else {
  92.          alpha = alphaMax;
  93.       }
  94.       x = parent.mouseX-8;
  95.       y = parent.mouseY+20;
  96.       //
  97.       if (x<0) {
  98.          x = 0;
  99.       }
  100.       if (x+width>pano.width) {
  101.          x = pano.width-width;
  102.       }
  103.       if (y+height>pano.height) {
  104.          y = pano.height-height;
  105.       }
  106.       if (!currentObject.visible) {
  107.          speed = alphaMinus;
  108.       }
  109.    } else {
  110.       if (alpha > alphaMin) {
  111.          alpha += speed;
  112.       } else {
  113.          alpha = alphaMin;
  114.          animationTimer.stop();
  115.          animationTimer = null;
  116.       }
  117.    }
  118. }
  119.  
  120. function remove () {
  121.    hotspots.removeEventListener(MouseEvent.MOUSE_OVER, doOver);
  122.    hotspots.removeEventListener(MouseEvent.MOUSE_OUT, doOut);
  123.    if (animationTimer!=null) {
  124.       animationTimer.stop();
  125.    }
  126.    animationTimer = null;
  127. }
Moderator Remark: added code tags. Please use [code=actionscript]{code goes here[/code] when posting actionscript code. Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

you can use htmlText property for tip_txt;
so, set
tip_txt.html = true;
(set this after the line: tip_txt.autoSize = TextFieldAutoSize.LEFT;)
then, instead of
tip_txt.text = text;
use tip_txt.htmlText = text;
And in the xml, for the italic words, place <i>word</i>
  • environmentflash
  • Newbie
  • Newbie
  • environmentflash
  • Posts: 7

Post 3+ Months Ago

IceCold wrote:
you can use htmlText property for tip_txt;
so, set
tip_txt.html = true;
(set this after the line: tip_txt.autoSize = TextFieldAutoSize.LEFT;)
then, instead of
tip_txt.text = text;
use tip_txt.htmlText = text;
And in the xml, for the italic words, place <i>word</i>



Hi IceCold,

Thanks for your reply. I have inserted the code into my Flash doc (using actionscript 3.0) but I am getting this error:

1119: Access of possibly undefined property html through a reference with static type flash.text:TextField.
Source: tip_txt.html = true;

Therefore the tooltip no longer works.

Sorry I just don't know enough about actionscript to be able to fix!

Your help again would be most appreciated.

enviro.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

seems that html property is no longer needed in AS3,
so remove that.
also check adobe live help: http://livedocs.adobe.com/flash/9.0/Act ... l#htmlText
  • environmentflash
  • Newbie
  • Newbie
  • environmentflash
  • Posts: 7

Post 3+ Months Ago

thanks!

my xml doc refuses to work when I insert the tags for italic...I'll keep trying and see it I can get it to work...thanks again for your help.

enviro
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

use CDATA. i.e.:
<xml ..... >
<items>
<item><![CDATA my text with tags which are <i> not allowed </i> by xml ]]></item>
</items>

the bolded red strings are the cdata start and end tag.
  • environmentflash
  • Newbie
  • Newbie
  • environmentflash
  • Posts: 7

Post 3+ Months Ago

Hi,

Thanks again!

I have tried this but I think the xml doc works differently..here is one of the tooltip elements I have tried to change:

<spot id="01rock" linked="pano01" url="/includes/water/virtual-tours/images/photo.png" pan="-1" tilt="0" depth="-120" scaleable="0" alt="Mangrove Nerita (Nerita balteata)"
onClick="01rockInfo.visible+=1" />
<spot id="01rockInfo" linked="pano01" url="images/smithspoint-01/image1.jpg" static="1" depth="120" visible="0"
smoothing="0" glow="100" glowColor="#FFFFFF" glowBlur="2" glowInner="1" shadow="1" shadowDistance="3" shadowAlpha="0.49"
onClick="visible=0" onOver="" onOut="" />

It's the alt tag (the words in brackets) that I want to partially italicise.

enviro
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

then just replace the brackets, like in this example.
Code: [ Select ]
function stringReplace(block:String, find:String, replace:String):String
{
    return block.split(find).join(replace);
}

var altString:String = "Mangrove Nerita (Nerita balteata)"; // this you'll get from
altString = stringReplace(altString, "(", "(<i>");
altString = stringReplace(altString, ")", "</i>)");
trace(altString);
  1. function stringReplace(block:String, find:String, replace:String):String
  2. {
  3.     return block.split(find).join(replace);
  4. }
  5. var altString:String = "Mangrove Nerita (Nerita balteata)"; // this you'll get from
  6. altString = stringReplace(altString, "(", "(<i>");
  7. altString = stringReplace(altString, ")", "</i>)");
  8. trace(altString);


in your code will be :
Code: [ Select ]
 var text:String = obj.attributes.getParam("alt");
  if (text!=null) {
    currentObject = obj;
    // if text contais \n, it is multilines
    if (text.indexOf("\\n")!=-1) {
     text = text.replace(/\\n/g, "\n")
    }
    text = stringReplace(text, "(", "(<i>");
    text = stringReplace(text, ")", "</i>)");
    ...
  1.  var text:String = obj.attributes.getParam("alt");
  2.   if (text!=null) {
  3.     currentObject = obj;
  4.     // if text contais \n, it is multilines
  5.     if (text.indexOf("\\n")!=-1) {
  6.      text = text.replace(/\\n/g, "\n")
  7.     }
  8.     text = stringReplace(text, "(", "(<i>");
  9.     text = stringReplace(text, ")", "</i>)");
  10.     ...
  • environmentflash
  • Newbie
  • Newbie
  • environmentflash
  • Posts: 7

Post 3+ Months Ago

thanks again,

i must admit this gives me the following error in flash:

1180: Call to a possibly undefined method stringReplace.

sorry, you've been most helpful but i seem to be a lost cause!

enviro
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

you forgot to copy the function stringReplace from the first code :)
  • environmentflash
  • Newbie
  • Newbie
  • environmentflash
  • Posts: 7

Post 3+ Months Ago

god..I'm such a flash amateur....this works in the flash file now...publishes fine.

does that mean in the xml doc instead of <i> and </i> I just use the brackets ( ) ? It still doesn't italicise.

Thanks again!

enviro

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 18 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.