?
Solved

Pass Variable between 2 SWF's (datagrid to xml connector)

Posted on 2005-02-28
17
Medium Priority
?
3,769 Views
Last Modified: 2012-08-14
Hi,

I have 2 swf's, first is a swf with datagrid (populated by xml) in a html file and  I have a second swf in a second html.

I'd like to select an item in the datagrid and then pass the info to the second swf which it will then use with an xml connect variable.

FYI - the second form is actually loading another xml file, the variable being passed to it is effectively the name of that XML file (without the .xml extention) so the orginal datagrid is simply listing the names of XML files to select.

on the datagrid swf I have a regular button which (with javascript) opens up a new browser window and the second swf embedded, this works fine. All I need help with is the difficult part, getting the variable from the datagrid and passing it to the second swf in the new browser window when the button is clicked on the first swf.

My experience is not very much..I am a complete fool with flash.

Any help appreciated.

Thanks
0
Comment
Question by:tmehmet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
17 Comments
 
LVL 9

Expert Comment

by:ddlam
ID: 13421270
LocalConnection can be used to call from one SWF to another SWF.
So you can execute another SWF function() from any SWF.

Just simply pass parameter into the function() and let the function() find out the same XML data

Great example with using localConnection:
http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_16243

localConnection action script dictionaray:
http://www.macromedia.com/support/flash/action_scripts/local_connection_objects/
0
 

Expert Comment

by:grzegorczyk
ID: 13421510
You need to pass the variable via the HTML in the pop up, then you need to read that variable back into the swf that is being popped up:

http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_20646702.html
0
 
LVL 5

Author Comment

by:tmehmet
ID: 13427404
Looks like LocalConnection is the way to go for me. I tried it out and it seems fine, I even used a variable instead of textbox to pass to the second swf.

All I need help with now is how to grab a selected item from a datagrid and put it into a variable (which I know I can pass to a second swf.)

I dont know how this aspect would be coded, any good examples of that would be very useful.

thanks
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 11

Expert Comment

by:Buffon
ID: 13427756
var myListener = new Object();
myListener.cellPress = function(event) {
    var cell = "(" + event.columnIndex + ", " + event.itemIndex + ")";
    trace("The cell at " + cell + " has been clicked");
};
grid.addEventListener("cellPress", myListener);
0
 
LVL 5

Author Comment

by:tmehmet
ID: 13427813
Hello again Buffon,

thanks for this.

based on the above info, is myListner the variable that I would pass to localConnect ?

how would this look if the cell had 'Microsoft' and I wanted to pass to localConnect as 'Microsoft.xml' ?

or would it be easier to add the .xml on the recieving swf when I use for XML connect?

thanks again, i greatly appreciate the help from everyone.
0
 
LVL 11

Expert Comment

by:Buffon
ID: 13427833
no no, cellPress is event that envoked when some cell is pressed in the datagrid, in this function as you see you can get the certain cell that was pressed and get the data from it and pass to localconnection, sorry I didnt explained it well :)


you can do it even easier, when you want to pass data to localconnection:
var variabletopass = yourdatagrid.selectedItem.data;
0
 
LVL 5

Author Comment

by:tmehmet
ID: 13427951
OK thanks, its starting to make sense, I will try it out. Hopefully it will still make sense when I try :-)


0
 
LVL 5

Author Comment

by:tmehmet
ID: 13440350
Hi, I tried the 'cellpress' code and it works great.. I think I did something wronge with the second part.

I thought I'd try doing a trace on the 'variablepassto'  suggestion;

>var variabletopass = yourdatagrid.selectedItem.data;

it tried 'trace(variabletopass);

a window came up but it contained the word 'variabletopass'

I am sure I did something silly like missed out some step in the process or I have the line in the wrong place.  FYI - I did change the 'yourdatagrid to my instance for datagrid

so close....yet so far :-)

i apologise for my ignorance, thanks for the help.

0
 
LVL 11

Expert Comment

by:Buffon
ID: 13440392
you did:
var variabletopass = yourdatagrid.selectedItem.data;
trace(variabletopass);


???? without any apostrophe?
0
 
LVL 5

Author Comment

by:tmehmet
ID: 13440532
yes, exactly as you have it, actually, i got desperate and tried these as well;

trace('variabletopass');
trace("variabletopass");

sorry about my typo in previous.
0
 
LVL 11

Expert Comment

by:Buffon
ID: 13440585
so put without apostrophe:
trace(variabletopass);

what do you get?
0
 
LVL 5

Author Comment

by:tmehmet
ID: 13440665
trace simply says;

variabletopass

(note: using MX 2004)



0
 
LVL 11

Expert Comment

by:Buffon
ID: 13440721
and if you put:

trace(yourdatagrid.selectedItem.data);

??



note: compile for actionscript2, player7.
0
 
LVL 5

Author Comment

by:tmehmet
ID: 13441176
OK, I will try this version of trace, thanks.
0
 
LVL 5

Author Comment

by:tmehmet
ID: 13443759
I get an 'undefined'

tried with variable, I also tried with this.mydatagrid.selectedItem.data as well in the trace.

I got  undefined, also.

I wonder if sorting the data is screwing it up. Here s  the whole actionscript.

var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function()
{
     //sort xml data in datagrid
       var arr:Array = new Array();
     for (var node:XMLNode = xml.firstChild.firstChild;node != null;node = node.nextSibling)
     {
          arr.push(node.firstChild.firstChild.nodeValue);
     }
     arr.sort();
     //trace(arr);
     for (var i=0;i<arr.length;++i)
          vendorList.addItem({name:arr[i]});
}

//event to select data in cell
var myListener = new Object();
myListener.cellPress = function(event) {
      //var cell = "(" + event.columnIndex + ", " + event.itemIndex + ")";
    //trace("The cell  " + cell + " has been clicked");
      var variabletopass = vendorList.selectedItem.data;
      trace(variabletopass);
};
vendorList.addEventListener("cellPress", myListener);

//Load local xml file
xml.load("vendorname.xml");

0
 
LVL 11

Accepted Solution

by:
Buffon earned 2000 total points
ID: 13445008
try:

var myListener = new Object();
myListener.cellPress = function(event) {
     //var cell = "(" + event.columnIndex + ", " + event.itemIndex + ")";
    //trace("The cell  " + cell + " has been clicked");
     var variabletopass = event.target.selectedItem.name;
     trace(variabletopass);
};
vendorList.addEventListener("cellPress", myListener);
0
 
LVL 5

Author Comment

by:tmehmet
ID: 13445223

it works !!

hooray.

excellent stuff.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question