creating multiple sharedobject dynamically - actionscript-3

I would like to dynamically create multiple sharedobject to create multi-login and I used the below code for that. But it throws error.Please post if there is any way to do it.
var k:Number=0;
var signup:SharedObject = SharedObject.getLocal("newSignUp");
signup_mc.signup_btn.addEventListener(MouseEvent.CLICK, signupcheck);
function signupcheck(event:MouseEvent):void {
newusername = signup_mc.username_txt.text;
newpassword = signup_mc.password_txt.text;
signup.data.nwusername+k = newusername;
signup.data.nwpassword+k = newpassword;
signup.flush();
k++;
}

Sure there would be errors. Assigning a+b=c will be wrong in most languages, I guess. If you want keys like nwusername0, nwusername1 etc you need to create keys in a correct way:
signup.data["nwusername" + k] = newusername;
signup.data["nwpassword" + k] = newpassword;

Related

AS3 Concatenating Reference Not Working

I'm struggling to concatenate a reference to a variable from a XML document. I'm trying to get:
chat_History.Msg.chatMessage1, chat_History.Msg.chatMessage2, chat_History.Msg.chatMessage3
It's instead over-riding the reference and turning into the value '0', '1', '2'. My code:
public function onReceivedChatData(Event:LoaderEvent)
{
var raw_user_info = LoaderMax.getContent("chatHistory");
var chat_History:XML = XML(raw_user_info);
if (chat_History.Msg)
{
trace("ReceivedChatData");
trace(chat_History);
for (var i:int = 0; i < int(chat_History.chatLength); i++)
{
var chatString:String = chat_History.Msg.chatMessage;
chatString += i.toString();
shopchatbox.shop_chat_window.text = shopchatbox.shop_chat_window.text + "\n" + chatString;
shopchatwidebox.shop_chat_window.text = shopchatwidebox.shop_chat_window.text + "\n" + chatString;
}
}
else
{
trace("chat_History XML Does Not Exist!!! Noooo :( ");
trace(chat_History);
}
}
The chatLength is 3, and it's calling the for statement 3 times correctly, however chatString isn't referencing it's variable (a string) correctly and only appears as '0', '1', '2'. I'm guessing I'm not concatenating this right and that's the problem, but I'm not sure how to do this?
Thanks!
chatString += i.toString();
That's going to give you the indexes 0, 1, 2. i just stores increments for iteration. Not the values from chat_History.Msg.chatMessage So you're adding i onto the content of chatString, not setting the variable name.
var chatString:String = chat_History.Msg.chatMessage;
chatString += i.toString();
Your code here says, take chatString, and set it to the value chat_History.Msg.chatMessage, then concatenate i as a String onto the content of chatString
If you wanted to access your variables by a variable name, I believe you'd do something like this;
var chatString:String = chat_History.Msg["chatMessage"+ String(i+1)];
So i+1 = 1, 2, 3. Which should mean you're accessing chat_History.Msg.chatMessage1, chat_History.Msg.chatMessage2 and chat_History.Msg.chatMessage3
Remove the line;
chatString += i.toString();
I'm afraid I can't test this as I don't have the XML code, but hopefully that gives you a general idea. I'm not 100% sure I've got calling a variable by a variable name correct, but it is possible to call a variable by a string name.
Edit:
After doing a little testing, the syntax appears to be correct, so that should get you the values from chat_History.Msg

How to assign variables to an instance name?

I have a code in AS3 that works perfectly, but I have mane repeated methods and functions, they are the same but using different instance names, so I would like to replace the instance name with a variable to avoid re-writing too much code.
here is part of my code:
urb_mc.urb.select(0);
trace("Urb: " + urb_mc.urb.selectedIndex);
I want to replace in this case "urb" with a variable so I tryed this:
var estado = currentLabel;
trace("este es mi estado " + estado);// this is ok = "urb"
//now I need to inset the variable in my code:
String(estado)+_mc.String(estado).select(0);//thi is so wrong!
trace("Urb: " + String(estado)+_mc.String(estado).selectedIndex);//thi is so wrong!
Any idea?
Thanks in advance
Try using:
this[estado+"_mc"][estado].select(0);
trace(this[estado+"_mc"][estado].selectedIndex);
Sorry for all the edits!
Thanks for the challenge! I learned there is such a thing as a multidimensional array operator for objects.
Part 2
Try this:
var tweenNameArray:Array = ["Name1", "Name2", "Name3"]
for (var i:int = 0; i > tweenNameArray.length(); i++){
var myTween:Tween = new Tween();
myTween.name = String("myTween_" + estado + "_in"); // You may want to try .toString();
}
Then referencing the tweens should work like this:
Tween(MovieClip(this.stage.getChildByName("myTween_" + estado + "_in")).whateverMethod(); // Try with and without the MovieClip().
I will say right now, it is not recommended to do things this way.

How write the values from the database into an array in Flash Builder 4

I want to display multiple images and when rollover above it i must get a tooltips (names). The same names are in the database mySQL. Naturally, to tooltips displayed without delay, preferably immediately put all the names from the database into an array and then manipulate them. Tell me please what I do wrong?
Php class to connect database:
public function getDataMean($id,$dir_id) {
$mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD);
mysql_query("SET NAMES 'utf8';");
mysql_query("SET CHARACTER SET 'utf8';");
mysql_query("SET SESSION collation_connection = 'utf8_general_ci';");
mysql_select_db(DATABASE_NAME);
$query = "SELECT name FROM files WHERE id='".$id."' AND dir_id='".$dir_id."'";
$result = mysql_query($query);
return $result;
}
FB4 code:
public var Names:Array = new Array();
public var textName:String;
protected function decks_clickHandler(event:MouseEvent):void
{
arrayOfNumber = new Array();
generateArray(minCount,maxCount);
randomize(arrayOfNumber);
var dir_id:int = 7;
card1.source = "http://***/gallery/7/"+String(arrayOfNumber[0])+".jpg";
card2.source = "http://***/gallery/7/"+String(arrayOfNumber[1])+".jpg";
card3.source = "http://***/gallery/7/"+String(arrayOfNumber[2])+".jpg";
for (var i:int=0; i<4; i++){
getDataMeanResult.token = authors.getDataMean(arrayOfNumber[i], dir_id);
Names[i] = getDataMeanResult.lastResult[0].name;
}
}
]]>
</fx:Script>
It's a bit hard to see from your code. But as I understood; you have some cards with in ID each, and you want to grab matching data from array when ever the user interacts with that card? - Correct?
If that is the case you properly want to use an associative array instead. In AS3 you use an instance of the Oject class as an associative array (yes that does seem a bit wierd). So maybe you should rewrite your code declaring Names as a Object instead of Array.
With that being said I can see one other problem with your code, you write Names[i] = ..., but you have not declared the size of the Array (or maybe that is what the generateArray function does?). Try using Names.push(getDataMeanResult.lastResult[0].name) instead.

Linq-to-SQL with a table valued UDF user defined function

I am new to Linq and trying to get a handle on how to bind a drop down to a SQL user defined function.
//Populate the Pledge dropdown
var db = new App_Data.MyDBDataContext();
int? partnerID = Convert.ToInt32(Request.QueryString["PartnerID"]);
var pledges =
from p in db.ufn_AvailablePledgesByPartner(partnerID)
select new
{
PledgeAndPartnerName = p.PledgeAndPartnerName,
PledgeID = p.PledgeID
};
DropDownList ddlPledgeID = (DropDownList)DetailsViewContribution.FindControl("DropDownListPledgeID");
ddlPledgeID.DataSource = pledges;
ddlPledgeID.DataTextField = pledges.PledgeAndPartnerName;
ddlPledgeID.DataValueField = pledges.PledgeID;
The current problem is the last 2 lines where I'm trying to reference properties of the anonymous class. "'System.Linq.IQueryable' does not contain a definition for 'PledgeAndPartnerName' and no extension method..." I naively thought the compiler was supposed to figure this out, but obviously I'm assuming C# is now more dynamic than it really is.
Thanks for any input.
Try this:
ddlPledgeID.DataTextField = "PledgeAndPartnerName";
ddlPledgeID.DataValueField = "PledgeID";

Dynamic variables in ActionScript 3.0

so.... eval() out of the question, any idea to do this? I also don't know how to use "this" expression or set() in actionscript 3 ( i seem couldn't find any complete reference on it ), just say through php file a multiple variable (test1, test2, test3,...) sent by "echo", how the flash aplication recieved it? I'm trying not to use xml on mysql to php to flash aplication. Simply how to change a string to a variable ?
example
(in as3-actions frame panel)
function datagridfill(event:MouseEvent):void{
var varfill:URLVariables = new URLVariables();
varfill.tell = "do it";
var filler:URLRequest = new URLRequest();
filler.url = "http://127.0.0.1/flashdbas3/sendin.php";
filler.data = varfill;
var filling:URLLoader = new URLLoader();
filling.dataFormat = URLLoaderDataFormat.VARIABLES;
filling.load(filler);
filling.addEventListener(Event.COMPLETE, datain);
function datain(evt:Event){
var arraygrid:Array = new Array();
testing.text = evt.target.Name2 // worked
// just say i = 1
i=1;
arraygrid.push({Name:this["evt.target.Name"+i],
Test:this.["evt.target.Test"+i]}); // error
//or
arraygrid.push({Name:this["Name"+i],
Test:this.["Test"+i]}); // error too
// eval() noexistent, set() didn't worked on actions frame panel
//?????
}
};
I hope it's very clear.
You could use this[varName] if I understand your question right.
So if varName is a variable containing a string which should be a variables name, you could set and read that variable like this:
this[varName] = "someValue";
trace(this[varName]);
Update:
In your example, you could try: evt.target["Test"+i] instead of Test:this.["evt.target.Test"+i]
If you have a set of strings that you'd like to associate with values, the standard AS3 approach is to use an object as a hash table:
var o = {}
o["test1"] = 7
o["test2"] = "fish"
print(o["test1"])