Adding To A String Based On A Count
I have a text fields with var names line1, line2....etc
When buttons are pressed I want to add to the existing string (in the case below 'tr') of one of the text boxs dependant my lineNum variable.
i = "line"+lineCount; i+="tr ";
I cannot get this to work when I use the lineCount to target the text box, if I just put in line1 += "tr" it works fine.
Hope someone can help Cheers Oll
FlashKit > Flash Help > Flash ActionScript
Posted on: 02-13-2003, 12:11 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Targeting Textfields Based On A Count
I have a text fields with var names line1, line2....etc
When buttons are pressed I want to add to the existing string in text box line1, line2 ...etc (in the case below 'tr') each time the targeted text box is dependant on the 'lineNum' variable.
i = "line"+lineCount;
i+="tr ";
I cannot get this to work when I use the lineCount to target the text box, if I just put in:
line1 += "tr"
...it works fine.
Hope someone can help
Cheers
ol
[CS3] Flash Count UP Clock Based In Another Timezone
I've found a few tutorials on count down clocks-- but I'm trying to make a count up clock based on a date in another time zone. Plus, when it reaches the final day, I need it to then play a movieclip.
Can anyone direct me to a good tutorial?
thanks for ANY input!!!
Count A Certain Word In A String
Hi there, i was wondering how i could count the number of times a certain word is used in a string? i cant seem to figure this out, is there a function for this?
Count A Certain Word In A String
Hi there, i was wondering how i could count the number of times a certain word is used in a string? i cant seem to figure this out, is there a function for this?
How To Count Word Frequency In A String?
Hi guys
I have a text string and I need to count the number of times a particular word is used in that string.
Can anyone point me in the right direction in how to count the number of times say a word is used in a string?
e.g. the word red in "i have a red car, i love the colour red, red is my favourite colour"
Thanks very much for your responses.
Byte Count Of String Object?
I need to send UTF-8 string data over an ActionScript socket. The protocol we're using requires that each message be prefaced with the byte count of the following payload. What is the best way to determine the byte (not character) count of a String object?
The only way I have found to do it is to instantiate a new ByteArray object, write my String into it with writeUTF, reset the ByteArray position property to 0, then check it's bytesAvailable, and finally subtract 2 from that value.
My two questions are: Is there a better way to do this? and, why do I need to subtract 2 bytes? Does the ByteArray have a BOM or ???
Count Number Of Specified Characters In A String
hiii,
for instance if i had the string, "til,is,amazing" and i had another string "til,is,even,more,amazing" how would I count the number of commas in each string? i need to find out which is the longer one....
what i have tried is splitting the string into an array, then tried checking the 4th value to see if it exists....
PHP Code:
if (til[3]=="") {
trace("shorter one!") } else {
trace("longer one!") }
}
that doesnt work though
thanks
Adding In Flash (hit Count?)
hello all,
Im looking to have a system so that numerical values are assigned to buttons, and each time these buttons are hit, it adds up the numbers. I also want this to span frames also, is this possible? can anyone point me in the right direction? cheers
[MX04] Count Amount Of Same Characters In String
Hi
How can I get Flash to return the amount of same characters used in one string.
Example: I type the phrase "Hello everybody" in a text field, press a button, and it tells me that there are "3 e; 2 l; 2 y; 1 h; ..." in that phrase.
I will convert the whole sentence toLowerCase() first, but after that, how can I add the same letters together?
Should I go thru ever charCode of the alphabet, and check how many letters in my sentence match that code?
Or would there be an easier way, where it will only look at the letters in the sentence?
Any ideas are appreciated.
Thanks.
E4X Get Xml Node Based On String?
if I have an xml like this
<stone_upcharges>
<diamond>126.00</diamond>
<alexandrite>99.00</alexandrite>
</stone_upcharges>
and I have a variable containing a string that matches the node name I want to get (for example var myVar:String = "diamond")
how can I get the node from that?
I tried stone_upcharges[myVar]; but it didn't work.
Does someone know how to do this?
Thanks!!
Is There A Way To Create An Object Based On A String Value?
Hi people!
I have a set of buttons that dispatch an event when clicked on. One thing im kind of struggling with is to create a new object based on button clicked.
If i click on contact us, i need to load up the contact us module. However im not really sure how to do this without hard coding the values.
an example of hard coding the issue i mean:
private var menuArray:Array = ("option1", "option2", option3");
.... on the buttons when clicked i dispatch a custom event
private function onClick(c:CustomEvent): Void
{
switch (c.id);
case 0:
currentSection = new Option1();
break;
// and so on and so forth
}
Is there a better way to go about this?
Thanks
Adding Scrollbars Based On Need
How would I go about having scrollbars show up only when a text field needs to be scrolled? The UIcomponent looks silly sitting there when there isn't any scrolling content.
-mx
Convert String Length To Pixel Based Value?
Hi all,
I can obtain the number of characters in a string using the 'length' action script command.
However, I need to know the pixel width of this 'length' - is their some magic formula for this - or better still a conversion tool out their somewhere?
Any ideas?
MacLemming.
Jumping To A Frame Based On Query String
Is there a way to jump to a specific frame in a flash movie based on the query string in the url?
For example, if the url ends in "flashmovie.html?frame=5" how can I grab the value of the frame variable and make the flash movie jump to that frame?
Load Vars From.asp Based On A Query String
In a certain part of my movie I want to load variables from an asp file based on a query string. I find out that loadVariablesNum("myAsp.asp?id=1") doesn't work.
How do I do it?
myAsp.asp generates specific results based on an ID...
Thanks!
[F8] Return String Based On Button Pressed?
I have a clip called "Cabell". It is one of many clips based on school names.
When I rollover the clip "Cabell" I need a pop-up to appear that says "Cabell Elementary". BUT, another clip named "Adams" should return "Bryan Adams High School". So they're not all elementaries.
My first thought was to just create a 1 item array like:
Cabell.Array = ["Cabell Elementary"];
and then code the clip like:
Cabell.onRollOver = function() { schoolName = this._name[0];}
But that doesn't seem to work. Any suggestions on how to cull the clip's name for use in determining the full name?
Eternal thanks, as always.
-Layne
Dynamic Text Based Off Query String
I just need a a dynamic text box to display whats in the query string like putting:
Code:
http://ww.mysite.com/flash/header.swf?MY TEXT HERE
Will make the .swf display dynamically, MYTEXT HERE. How is this done?
Array Length, When Index Is String-based
Hi everyone
just a simple example:
var a = new Array()
a["apple"] = "red"
a["orange"] = "orange"
a["banana"] = "yellow"
trace(a.length) //returns 0
Why on earth does that happen? Anyone knows a way to get it work?
I should try something with for(var item in a)
[F8] Dynamic Height Rescale (based On String.length)
Hi there...
Okay what I after is how to detect the length of the string populated from array...then auto rescale the height of the title_mc as shown in my AS as well as the dynamic created textfield ..so the textfield will display long string + "newline" for long string...(autowrapper)..
eg:
// for short text keep remain the standard size of height
mc.title_mc.tf.text = "short text";
//for long string it will expandable the title_mc.height as well...dynamically
mc.title_mc.tf.text = "standard width title_mc"+newline;
//by the time string move to newline the title_mc.height also will increase
so how to determines the long string and auto rescale the title_mc.height
here's the code currently I'm using...
Code:
stop();
var sometesttext:Array = new Array("super super super longggggggg textttttttt iiiiiiiii guesssssssssss","intermediate text","short text");
var len:Number = sometesttext.length;
this.createEmptyMovieClip("mc",this.getNextHighestDepth());
for(var i=0;i<len;i++){
var mc = mc.attachMovie("bubbles","bubbles"+i,mc.getNextHighestDepth());
mc._y = 50;
mc._x = 20+mc._width*i;
mc.ivar = i;
mc.title_mc.createTextField("tf",100,mc.title_mc._x,mc.title_mc._y,mc.title_mc._width,mc.title_mc._height);
mc.title_mc.wordWrap = true;
mc.title_mc.multiline = true;
////////////////////////////////////////////
mc.title_mc.tf.text = sometesttext[mc.ivar];
//******** this portion how to determines in order to display
short text and long text..
///////////////////////////////////////////
//setting txtfield format
myformat = new TextFormat();
myformat.color = 0xffffff;
mc.title_mc.tf.setTextFormat(myformat);
}
thanks in advanced
CreateTextField Setting Width Based On String Length
I wonder if there is a way to easily calculate how wide to make a textfield that you create dynamically with createTextField based on the length of a string that is passed as an argument. In other words, if you know the font size you plan on using, is there a way to figure out how many pixels you need? Thanks in advance to anyone who can offer some assistance.
String.split To Time-based Array For Button URL
Hi folks -
So this is part of the ongoing video player I'm working on. Here's the problem setup:
client needs to have tracking URLs applied to an invisible button during commercials (usually 30 seconds each). there's some javascript controls that populate the click URL, which are separated by ",". The tracking URLs could be between one and 3 URLS per 30 second commercial. If it's 3, then the URL changes every 10 seconds.
Right now I have the button working - sort of. The javascript does populate the invisible button, however when you click on the button during the commercial you get three popup windows rather than one per commercial block (i.e. there could be three different popups with three different URLs - but not at once, just per click).
Code is below / attached.
however, when I do add in that code it seems to just loop and stops the button action. Mostly the "if" statement is the problem.
So any clue on how I can get the URLs to populate one at a time per time segment?
Attach Code
Button Code:
var my_str:String = thisAd;
var my_array:Array = my_str.split(",");
var CurrentTime:Number = Math.floor(playFlvStream.time / duration * 100);
var percent_interval = Math.floor(100 / my_array.length);
var percent_trigger = i * percent_interval;
adButton_mc.onRelease = function()
{
for (var i = 0; i<my_array.length; i++) {
getURL(unescape(my_array[i]),"_blank");
}
}
What I need to be able to do is add in something like this:
for (var i = 0; i<adArray.length; i++) {
var percent_trigger = i * percent_interval;
if(CurrentTime == percent_trigger){
getURL(unescape(my_array[i]),"_blank");
}
Dynamic Height Rescale (based On String.length)
Hi there...
Okay what I after is how to detect the length of the string populated from array...then auto rescale the height of the title_mc as shown in my AS as well as the dynamic created textfield ..so the textfield will display long string + "newline" for long string...(autowrapper)..
eg:
// for short text keep remain the standard size of height
mc.title_mc.tf.text = "short text";
//for long string it will expandable the title_mc.height as well...dynamically
mc.title_mc.tf.text = "standard width title_mc"+newline;
//by the time string move to newline the title_mc.height also will increase
so how to determines the long string and auto rescale the title_mc.height
here's the code currently I'm using...
Code:
stop();
var sometesttext:Array = new Array("super super super longggggggg textttttttt iiiiiiiii guesssssssssss","intermediate text","short text");
var len:Number = sometesttext.length;
this.createEmptyMovieClip("mc",this.getNextHighestDepth());
for(var i=0;i<len;i++){
var mc = mc.attachMovie("bubbles","bubbles"+i,mc.getNextHighestDepth());
mc._y = 50;
mc._x = 20+mc._width*i;
mc.ivar = i;
mc.title_mc.createTextField("tf",100,mc.title_mc._x,mc.title_mc._y,mc.title_mc._width,mc.title_mc._height);
mc.title_mc.wordWrap = true;
mc.title_mc.multiline = true;
////////////////////////////////////////////
mc.title_mc.tf.text = sometesttext[mc.ivar];
//******** this portion how to determines in order to display
short text and long text..
////////////////////////////////////////////
//setting txtfield format
myformat = new TextFormat();
myformat.color = 0xffffff;
mc.title_mc.tf.setTextFormat(myformat);
}
thanks in advanced
Adding Perspective To Vector Based TEXT
Does anyone know how to distort vector based text in Flash MX to give the illusion of adding perspective. I know I can do a bitmap converion but it defeats the purpose of creating the text with vectors. Is it possible with Flash MX or do I have to use Illustrator and import the newly designed vector elements into my file? Thanks for the help.
Adding Parent Tag Based On Child Attribute
Hello everyone
May i know how i can add a parent tag to my xml based on child node attributes.For eg if this is my xml
<data>
<mango attr='sweet'>mangoCategory</mango>
<orange attr='sour'>orangeCategory</orange>
<chilly attr='spicy'>chillyCategory</chilly>
<banana attr='sweet'>bananaCategory</banana>
</data>
The o/p should look like this
<data>
<attr='sweet'>
<mango attr='sweet'>mangoCategory</mango>
<banana attr='sweet'>bananaCategory</banana>
</attr>
<attr='sour'>
<orange attr='sour'>orangeCategory</orange>
</attr>
<attr='spicy'>
<chilly attr='spicy'>chillyCategory</chilly>
</attr>
</data>
Adding A Mc From The Library Based On The Users Choice
Is there any way to do this? I only want one MC added with the same instance name based on the users choice.
if(event.target.name == "faceType1_mc") {
var myFace_mc:faceType1 = new faceType1();
}
else if(event.target.name == "faceType2_mc") {
var myFace_mc:faceType2 = new faceType2();
}
Help For Adding More Tiles To Tile Based As3 Game
im playing around with this code, http://www.emanueleferonato.com/2008...flash-step-15/
right now it is only set up to use one tile from the movieclip platform_tile
how would i make it so i can make an unlimited number of tiles?
from the little as3 knowledge i have, would i make it so you load platform_tile+i (number of tile in movieclip which would equal the number on the array?
this is the map code:
Code:
private function BuildMap(){
Map_data.Setup(); // setup data from extern file
level = Map_data.level1; // get data from extern file
for(var t = 0; t < level.length; t++){
for(var u = 0; u < level[t].length; u++){
if(level[t][u] != 0){ //if the data is not null
var new_tile:platform_tile = new platform_tile; //than build a tile
addChild(new_tile); //put it on the screen
new_tile.gotoAndStop(1);
new_tile.x = u * 25;
new_tile.y = t * 25;
tiles.push(new_tile); //put it in an array
}
}
}
}
}
}
thank you
-joey
Adding More String
I am creating a program that has a Output Box . A Input Box, and a Send Button. I created a Script that allows the user to put some string into the Input Box, and once they press send, it will display on the output box. I want to have it where once they press send. They can type in some different text and instead of the different text replacing the previous text displayed in the box, it only adds on . For example
send.OnPress = function() {
outputbox.text = inputbox.text;
}
Say I typed in Hello into the inputbox.text. Then the string "Hello" will display in the output box. Now say I typed World the second time. Then the word "World" will replace "hello". I want it to instead say "Hello World" once I type in the word world the second time.
Edited: 03/14/2007 at 12:51:48 PM by numerical07
Actionscript For Adding Sound To An XML Based Photo Gallery
I was wondering how I could add sound to a gallery that is driven by xml.
I have a gallery that loads the picture, Title and description. the gallery is downloadable here. http://www.flashmo.com/prev...o_133_fisheye
The regular gallery loads a web page when the picture is clicked. I am trying to make each picture load a different mp3.
I have the general Idea of how it would be done but I don't know how put it to actionscript.
I figured you would basically create a sound object that loads the specific mp3 from the xml file when the picture is clicked from the gallery.
Can Anyone help me with this?
I think I might have some what of the idea right but I get an error everytime I load the swf file.
"ArgumentError: Error #2068: Invalid sound.
at flash.media::Sound/play()
at MethodInfo-6()"
If anyone could help me with this I would greatly appreciate it.
Here is the actionscript.
Code:
// Copyright © flashmo.com
// Developed by Min Thu
stop();
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import fl.transitions.Tween;
import fl.transitions.easing.*;
var filename_list = new Array();
var url_list = new Array();
var url_target_list:Array = new Array();
var title_list = new Array();
var description_list = new Array();
var song_list = new Array();
var i:Number;
var j:Number;
var tn:Number = 0;
var default_scale:Number = 0.6;
var new_scale:Number;
var center_x:Number = tn_group_mask.x + tn_group_mask.width * 0.5;
var half_of_tn_width:Number = 80;
var current_mc:MovieClip;
var total:Number;
var flashmo_xml:XML = new XML();
var folder:String = "thumbnails/";
var xml_loader:URLLoader = new URLLoader();
xml_loader.load(new URLRequest("flashmo_129_thumbnail_list.xml"));
xml_loader.addEventListener(Event.COMPLETE, create_thumbnail);
var thumbnail_group:MovieClip = new MovieClip();
stage.addChild(thumbnail_group);
thumbnail_group.mask = tn_group_mask;
thumbnail_group.x = tn_group.x;
thumbnail_group.y = tn_group.y;
tn_group.visible = false;
tn_title.text = "";
tn_desc.text = "";
tn_url.text = "";
function create_thumbnail(e:Event):void
{
flashmo_xml = XML(e.target.data);
total = flashmo_xml.thumbnail.length();
for( i = 0; i < total; i++ )
{
filename_list.push( flashmo_xml.thumbnail[i].@filename.toString() );
url_list.push( flashmo_xml.thumbnail[i].@url.toString() );
title_list.push( flashmo_xml.thumbnail[i].@title.toString() );
description_list.push( flashmo_xml.thumbnail[i].@description.toString() );
song_list.push (flashmo_xml.thumbnail[i].@filename.toString() );
load_tn();
stage.addEventListener(Event.ENTER_FRAME, fisheye );
}
function load_tn():void
{
var pic_request:URLRequest = new URLRequest( folder + filename_list[tn] );
var pic_loader:Loader = new Loader();
pic_loader.load(pic_request);
pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_loaded);
tn++;
}
function on_loaded(e:Event):void
{
if( tn < total )
{
load_tn();
}
var flashmo_bm:Bitmap = new Bitmap();
var flashmo_mc:MovieClip = new MovieClip();
flashmo_bm = Bitmap(e.target.content);
flashmo_bm.x = - flashmo_bm.width * 0.5;
flashmo_bm.y = - flashmo_bm.height * 0.5;
flashmo_bm.smoothing = true;
var bg_width = flashmo_bm.width + 10;
var bg_height = flashmo_bm.height + 10;
flashmo_mc.addChild(flashmo_bm);
flashmo_mc.graphics.lineStyle(1, 0x666666);
flashmo_mc.graphics.beginFill(0xFFFFFF);
flashmo_mc.graphics.drawRect( - bg_width * 0.5, - bg_height * 0.5, bg_width, bg_height );
flashmo_mc.graphics.endFill();
flashmo_mc.name = "flashmo_" + thumbnail_group.numChildren;
flashmo_mc.buttonMode = true;
flashmo_mc.addEventListener( MouseEvent.MOUSE_OVER, tn_over );
flashmo_mc.addEventListener( MouseEvent.MOUSE_OUT, tn_out );
flashmo_mc.addEventListener( MouseEvent.CLICK, tn_click );
flashmo_mc.scaleX = flashmo_mc.scaleY = default_scale;
flashmo_mc.x = thumbnail_group.numChildren * 94;
thumbnail_group.addChild(flashmo_mc);
}
function tn_over(e:MouseEvent):void
{
var mc:MovieClip = MovieClip(e.target);
var s_no:Number = parseInt(mc.name.slice(8,10));
if( s_no > 1 )
thumbnail_group.addChild( thumbnail_group.getChildByName("flashmo_" + (s_no-2) ) );
if( s_no > 0 )
thumbnail_group.addChild( thumbnail_group.getChildByName("flashmo_" + (s_no-1) ) );
if( s_no < thumbnail_group.numChildren - 2 )
thumbnail_group.addChild( thumbnail_group.getChildByName("flashmo_" + (s_no+2) ) );
if( s_no < thumbnail_group.numChildren - 1 )
thumbnail_group.addChild( thumbnail_group.getChildByName("flashmo_" + (s_no+1) ) );
thumbnail_group.addChild( mc );
tn_title.text = title_list[s_no];
tn_desc.text = description_list[s_no];
tn_url.text = url_list[s_no];
}
function tn_out(e:MouseEvent):void
{
tn_title.text = "";
tn_desc.text = "";
tn_url.text = "";
}
function tn_click(e:MouseEvent):void
{
var mc:MovieClip = MovieClip(e.target);
var s_no:Number = parseInt(mc.name.slice(8,10));
var s:Sound = new Sound();
var sc:SoundChannel = s.play();
navigateToURL(new URLRequest(song_list[s_no]));
}
}
function fisheye(e:Event):void
{
thumbnail_group.x -= ( mou*** - center_x ) * 0.05;
if( thumbnail_group.x > tn_group_mask.x + half_of_tn_width )
{
thumbnail_group.x = tn_group_mask.x + half_of_tn_width;
}
else if( thumbnail_group.x < tn_group_mask.x - thumbnail_group.width + tn_group_mask.width )
{
thumbnail_group.x = tn_group_mask.x - thumbnail_group.width + tn_group_mask.width;
}
if( mouseY > tn_group_mask.y && mouseY < tn_group_mask.y + tn_group_mask.height )
{
for( j = 0; j < thumbnail_group.numChildren; j++ )
{
current_mc = MovieClip(thumbnail_group.getChildAt(j));
var distance:Number = Math.sqrt(
Math.pow( Math.abs( stage.mou*** - (current_mc.x + thumbnail_group.x) ) , 2)
+ Math.pow( Math.abs( stage.mouseY - (current_mc.y + thumbnail_group.y) ) , 2)
);
new_scale = 1 - ( distance * 0.002 );
current_mc.scaleX += (new_scale - current_mc.scaleX) * 0.2;
current_mc.scaleY += (new_scale - current_mc.scaleY) * 0.2;
if( current_mc.scaleX < default_scale )
current_mc.scaleX = current_mc.scaleY = default_scale;
}
}
else
{
for( j = 0; j < thumbnail_group.numChildren; j++ )
{
current_mc = MovieClip(thumbnail_group.getChildAt(j));
current_mc.scaleX += (default_scale - current_mc.scaleX) * 0.2;
current_mc.scaleY += (default_scale - current_mc.scaleY) * 0.2;
}
}
}
And here is the XML shortened.
Code:
<thumbnails>
<thumbnail filename="flashmo_128_elegant.jpg" url="http://www.flashmo.com/preview/flashmo_128_elegant" target="_parent._parent"
title="Item No. 1 (128 elegant)"
description="Elegant Design - Flash website template, subpages for products, AS3 contact form"
song="Sound.mp3"/>
<thumbnail filename="flashmo_127_curtain.jpg" url="http://www.flashmo.com/preview/flashmo_127_curtain" target="_parent._parent"
title="Item No. 2 (127 curtain)"
description="Curtain template for making simple Flash websites including ActionScript 3 + PHP contact form"
song="Sound.mp3"/>
<thumbnail filename="flashmo_126_envelope.jpg" url="http://www.flashmo.com/preview/flashmo_126_envelope" target="_parent._parent"
title="Item No. 3 (126 envelope)"
description="Envelope Template with drag N drop Flash photo gallery, ActionScript 3.0"
song="Sound.mp3"/>
</thumbnails>
Adding Numbers To A String
How do I add a number to a string . Here is what I have
Code:
on (rollOver) {
isOver+="b"+1;
I want it to show in a variable as b1 and when you roll over it again it will show b2 . As is now it just keeps adding it like b1b21b12 or something like that .
Adding Javascript To A String?
on (release) {
var strURL = "http://207.21.247.39/html/seriespop.asp?seriesid="+id;
getURL (strURL, "_blank");
trace ("URL "+strURL);
}
I have this script to pull up a URL - how to I a [javascript: openWindow] command to this string???
I would be grateful for any suggestions!
Cheers
Adding "'s To An XML String
I have in my AS an HTML string sent from javascript.
The string in Firefox works great, but in IE the class names and other parameters loose thor "'s ... example class="test" is now class=test
so what is the easiest way to put the quotes BACK in attributes of this XHTML XML string?
Adding Spaces To A String
Hi, I have a simple question... hope you can help me...
I have a string like this: "a b". As you can see, it has a lot of space between the two letters. Now, when I assign that string to a TextField, it crops all the spaces in the middle leaving just 1 simple space like so: "a b".
What I need, is a way to put lots of spaces between two characters in a TextField. In other words, I need the TextField to show the real content of the string... does anyone knows how to do that?
Thanks
EDIT: Ok, even the forum trimmed my question... the real string has a lot of blank spaces between the letters "a" and "b", that's what I want the TextField to show...
Adding Info To A String
Okay,
I have a string of info I am importing into Flash and need to know how to add additional info to a specific string from the XML with AS3. Does anyone know how to use RegExp? I can't seem to get it to work. I need to add a file extension, height and width to an image that lacks this info. Thanks for any help or suggestions.
David
Code from main timeline with failed RegExp code (no errors, just does not work):
ActionScript Code:
import com.me.xml.*;
import com.me.php.*;
import fl.controls.*;
import fl.data.*;
var info_txt:TextArea = panel_mc.main_mc.info_txt;
var episode_cb:ComboBox = panel_mc.main_mc.episode_cb;
var date_txt:TextField = panel_mc.main_mc.date_txt;
var view_btn:Button = panel_mc.main_mc.view_btn;
var grabber:Grabber = new Grabber();
var reader:RSSReader = new RSSReader();
function dataGrabbed(event:Event):void
{
info_txt.text = "processing xml data";
reader.addEventListener(Event.COMPLETE, rssProcessed);
reader.processXML(new XML(grabber.data));
}
function RegExpExample():void {
var formalGreeting:String = 'img src="http://image.shopzilla.com/resize?sq=100&uid=\d{9}"';
}
function informalizeGreeting(str:String):String {
var pattern:RegExp = new RegExp('img src="http://image.shopzilla.com/resize?sq=100&uid=\d{9}"', "gim");
return str.replace(pattern, 'img src="http://image.shopzilla.com/resize?sq=100&uid=/d{9}/.jpg" width="100" height="50"');
}
function rssProcessed(event:Event):void
{
var episodeDP:DataProvider = new DataProvider();
for each(var item:XML in reader.episodes)
{
episodeDP.addItem({label:item.title});
}
episode_cb.dataProvider = episodeDP;
episode_cb.addEventListener(Event.CHANGE, changeSelection);
episode_cb.selectedIndex = 0;
updateText();
view_btn.addEventListener(MouseEvent.CLICK, viewOnline);
}
function viewOnline(event:MouseEvent):void
{
navigateToURL(new URLRequest(reader.episodes[episode_cb.selectedIndex].link));
}
function changeSelection(event:Event):void
{
updateText();
}
function updateText():void
{
var date:String = reader.episodes[episode_cb.selectedIndex].pubDate;
date = date.substr(0, date.length-14);
info_txt.htmlText = reader.episodes[episode_cb.selectedIndex].description;
date_txt.text = date;
}
grabber.load("grabber.php", "http://www.shopzilla.com/14G_-_feed_id--4/rss.xml");
grabber.addEventListener(Event.COMPLETE, dataGrabbed);
Adding String Items In Arrays?
This is probably simple enough, just can't figure it out:
I have 4 buttons. When they are chosen they replace
newMix = [0,0,0,0]
to
newMix = ["a","b", "c","d"]
(of course some buttons may not be chosen)
what I want to happen is to ad the elements of newMix
so if someone picked a b and d, newMix = ["a","b",0,"d"] would return a value of "abd"
esentially, I'm searching for how to get rid of the commas in the array listing.
Anyone have any ideas?
Adding A Property To A Variable String
Hi there, trying to write a little code, I have it working up to the trace but I cant work out how to get the second function to work.
I want to access the following button:
'_root.mapBig.map.shanghaiButton' with a '.onRollOver' trigger, however I cant figure out how to make the sCityPath work with the .onRollOver.
function cityLoader(sCurrentCity:String):Void {
var sCurrentCityButtonName:String = sCurrentCity+"Button";
var sCityPath:String = "_root.mapBig.map."+sCurrentCityButtonName;
trace (sCityPath);
sCityPath.onRollOver = function() {
....
};
};
cityLoader("Shanghai");
Any ideas would be great.
Trouble Adding Commas To String
I'm using code I found on this site to add commas to a large number (so that a number like 1000000 appears as 1,000,000). Below is the actionscript I'm using.
When I define the variable debt as any number, the script works perfectly. But if I define debt as a variable passed to the movie from a PHP file, then the script puts the commas in the wrong places (i.e., 10,000,00). Can anyone explain to me why this would happen, and how to fix it?
var input = debt;
var inputString = input.toString();
var finalString = "$";
var count = 0;
var tempString = "";
for (var i = inputString.length-1; i>=0; i--) {
count++;
tempString += inputString.charAt(i);
if ((count%3 == 0) && (i - 1 >= 0)) {
tempString += ",";
}
}
for (var k = tempString.length; k>=0; k--) {
finalString += tempString.charAt(k);
}
return(finalString);
AS2:: Adding String Values To An Array
I'm not too sure how to go about this or if it is possible. But is it possible to add the values from a string to an array?
For example my string looks like this:
var bookmarks:String = "book1, book2, book3";
And I need to add these values to the end of an array?
Thanks for any advice or help.
Word Count (or Character Count) For An Input Field
How would I create a word/character count field to count down characters used when typed into an input filed.
i.e. input field has a maxChar=255. I want the user to see the chars count down from 255, so they'll know how many they have left.
I figure it would be along the lines of wordCountField=maxChar-currentNumOfChars...would that be right?
Thanks.
Word Count (or Character Count) For An Input Field
How would I create a word/character count field to count down characters used when typed into an input filed.
i.e. input field has a maxChar=255. I want the user to see the chars count down from 255, so they'll know how many they have left.
I figure it would be along the lines of wordCountField=maxChar-currentNumOfChars...would that be right?
Thanks.
Adding Commas To Turn String Into Dollars
Hi all,
I have a dynamic textfield that is bringing in a number from a txt file.
the number is displaying like this:
1853600
I want it to look like this:
$1,853,600
I can have it display as dollars in another field if that's how this gets done.
oh...How would I adjust it to deal with a number in the tens of millions?
Thanks
-Lemorris
Dynamically Adding Custom Classes Via String
I have a bunch of MC's in my library, each with custom classes, base class MovieClip.
Normally, I would add them like this:
var myMovieA:MovieClip = new CustomMCa();
var myMovieB:MovieClip = new CustomMCb();
var myMovieC:MovieClip = new CustomMCc();
...but what if the "CustomMC" needs to dynamic? i.e. perhaps based on a string variable? Other than a long switch/case or if/then checking against the string, is there any way to achieve that?
Problems Adding Methods To String Class
I'm trying to add some new methods to the built in String class. I've tried two new methods so far. One of them (entitiesConvert, which is by far the most complex) seems to work OK (at least, it doesn't give any compiler errors). The other (pad, which is just a few lines of code) doesn't. Whenever I use the new pad() method, either inside the entitiesConvert method, or elsewhere in my code, I get a "no such method" error.
My code is below. Can anyone see what's wrong with the pad() method?
Thanks - Rowan
// String pad method.
// If len is negative, pads on the left, if positive, to the right.
// Pads to length abs(len) with the first character of str.
// str defaults to " ".
String.prototype.pad = function(len:Number, str:String):String
{
var abslen:Number = Math.abs(len);
var s = abslen-this.length;
if (s <= 0) return this;
if (!str.length)
{
str = " ";
}
else
{
str = str.substring(0,1);
}
var p = "";
while (s > 0)
{
p += str;
s--;
}
if (len >= 0)
{
return (this + p);
}
else
{
return (p + this);
}
}
// Convert HTML entities into their corresponding Unicode characters
String.prototype.entitiesConvert = function():String
{
var str:String = this;
// create the entity mapping array
// which allows decoding html entities into their unicode equivalents
var aryEntities:Object = new Object();
aryEntities[" "] = "u00A0"; // non-breaking space
aryEntities["¡"] = "u00A1"; // inverted exclamation mark
aryEntities["¢"] = "u00A2"; // cent sign
aryEntities["£"] = "u00A3"; // pound sign
// Lots more entities go here...
for(var entity:String in aryEntities)
{
str = str.split(entity).join(aryEntities[entity]);
}
var strptr:Number = 0;
var begnum:Number;
var endnum:Number;
var numstr:String;
var numtyp:String;
var num:Number;
while ((begnum = str.indexOf("&#", strptr)) > -1)
{
if ((endnum = str.indexOf(";", begnum + 2)) > -1)
{
numstr = str.substring(begnum + 2, endnum);
numtyp = numstr.substring(0, 1);
if (numtyp == "x" || numtyp == "X")// Hex number.
{
if ((num = parseInt(numstr.substring(1), 16)) == NaN)// Not a valid hex number.
{
strptr = endnum + 1;
continue;
}
}
else// Decimal number.
{
if ((num = parseInt(numstr)) == NaN)// Not a valid decimal number.
{
strptr = endnum + 1;
continue;
}
}
// The first version of this line causes a "no such method" error
// str = str.substring(0, begnum) + "u" + num.toString(16).toUpperCase().pad(-4,"0") + str.substring(endnum + 1);
// The second version of this line compiles without error.
str = str.substring(0, begnum) + "u" + num.toString(16).toUpperCase() + str.substring(endnum + 1);
}
else
{
strptr = begnum + 2;
}
}
return str;
}
Adding String Data To An Expression For Evaluation
Hi, I have the following function:
Code:
getInfo = function (input, arrayData, desiredResult)
{
for (i = 0; i < arrayData.length; i++)
{
if (arrayData[i].button == input)
{
return arrayData[i].desiredResult;
}
}
};
arrayData is a multidimensional array containing objects.
What I need returned is arrayData[i].desiredResult, where desiredResult is a string passed to the function. For example:
test("dogs", theArray, "color") needs to return the evaluated value of arrayData[i].color. How can I achieve this? Thanks!
Grabbing Correct Array And Placing Adding To String
Hey yall I am trying to grab a movie clip instance which is amongst an array and attach it to a string.
I am trying this:
Code:
stateArray = new Array(AL,AK,AZ, ect....);//names of mc instances
for (var i = 0; i<stateArray.length; i++) {
stateArray[i].onRelease = function() {
getURL("/pagoso/browsestate.aspx?cat="+cat+"&state="+stateArray[i], "_self");
};//each mc onRelease will grab "cat" from string and add its respective state Array to String
}
Results in state being undefined state;
Have tried this:
Code:
stateArray[i].onRelease = function() {
getURL("/pagoso/browsestate.aspx?cat="+cat+"&state="+stateArray[0], "_self");
};
}
Resulting in:
/pagoso/browsestate.aspx?cat=8&state=_level0.AL
and if I do just stateArray it adds all the states with _level0.AL, _level0.AK ect....
How come I cant get it to just grab MC instance?
Top 5 Maker: Merging Two Arrays And Adding The Values Of Matching String Entries
Hello All,
I've searched a bit and not found any discussions regarding what I'm looking for. I'm not looking for coded answers but would rather hear opinions on best approach.
I am creating a topFive Application using custom classes.
The simplest way to describe this is that two people can enter 5 strings and two top 5 lists are made, merged and a new top 5 is displayed.
Basically, I want to compare two multi-dimensional arrays that both contain a string with a value attached to it. I want to combine these arrays, and while doing so when a common string is found, I need it to add the two values and remove the two duplicates. (i'll get into an example below).
currently, multiple users (1 & 2 for now), can enter a string and a value is given to it. The strings are then made into a displayed list (outputting the multi-dimensional array into a text box "String:Value"). I plan on merging these two muli-dimensional arrays, and sorting by Value of the entry. When a duplicate entry is found, the values are added together and one entry is made with the new value and the other two entries are discarded.
I need advice on three steps:
1. Merging two MD arrays with a string and a value in each.
2. Finding duplicates by comparing the strings.
3. merging the duplicates and adding their value (creating a new entry and deleting the other two)?
Currently this is whats going on:
User 1 --->makes 5 string(str) entries ----->descending (nameValue) value added to each entry ------> entry and value make an array called u1_names. That is entered into a nameEntryClass that holds s:String and v:value
ActionScript Code:
u1_names.push(new nameEntry(str, nameValue));
trace in the app outputs User1 entries like this;
ActionScript Code:
trace(cmi.u1_names);
User1 entry 1:5,
User1 entry 2:4,
User1 entry 3:3,
User1 entry 4:2,
User1 entry 5:1
(This would be repeated for User 2)
Now before I collect the data from User 2 I want to know the best way about doing this.
So I need the App to merge, compare, add and delete redundant entries (see three steps above) from User 1 and User 2.
Is this possible?
Can anyone point me in the direction of a tutorial or a key word (I found recursive trace post in AS2 that looked close to what I'd need) that I could find more information regarding any of this..
Thanks in advance,
Switch Simple Count Up To Count Down
Hello...first post for me after finding a lot of great info here.
I've found a simple count up script over on Actionscript.org
var count:Number = 0;
var maxNum:Number = 1250;
var num:Number = 1;
this.createTextField("txt", this.getNextHighestDepth(), 0, 0, 100, 50);
onEnterFrame = function () {
count += num;
if (count >= maxNum) {
num = 0;
txt.text = "125.0";
} else {
var v = count / (maxNum / 125);
txt.text = v;
var str = String(v);
var io = str.indexOf('.');
if (io == -1)
{
txt.text = v + '.0';
}
}
}
This works great for my use, but now I am trying to figure out how to make it count down. I've tried changing everything to opposites like count=1250 and maxNum=0 (I think this would be the minNum instead), count+=num to count-=num, and count>=maxNum to count<=maxNum. But I'm stuck...any ideas? I'll search through the forum to see if I can find any info, but if anyone has a answer, that would be great. Thank you very much!
Count Down Timer Changes In Count Up
Is it possible to make a count up timer (from a specific date, birthday for exemple) from the count down timer ?
I've tried to change a few things (I'm very bad in programming) but I can't get the date properly.
If not, do somebody know a count up timer (.fla) that I can use ?
Thanks, thanks, thanks
Frankie
Count Down Timer Changes In Count Up
Is it possible to make a count up timer (from a specific date, birthday for exemple) from the count down timer ?
I've tried to change a few things (I'm very bad in programming) but I can't get the date properly.
If not, do somebody know a count up timer (.fla) that I can use ?
Thanks, thanks, thanks
Frankie
How To Make The Event Based Block Into Procedure Based
i'd like to do something like this
var a = getXML("xmlfile.xml");
However, the xml component is event based. I only get data when onLoad is fired.
How to wrap this kind of event based function into my custom function?
|