Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sharedobject without using input text field 1

Status
Not open for further replies.

Flashoid

Technical User
Dec 11, 2002
163
US
I am struggling to find a solution to a shared object problem. I am trying to push data without a user having to enter anything into a text field. My goal is for a user to start on a home page swf, click on a link taking them to another swf. Once the user clicks through this other swf they encounter a "Return to Menu" button. When the user clicks on the Return to Menu button a bit of data (number or letter I preselect) is written to a sharedobject. When the user re-enters the Main swf that number or letter from the other screen is displayed. I am using this to indicate to the user that they have already visited this screen. There will be many screens that the user can enter so this will be a good way to visually indicate to the user that they have already viewed a particular screen. I have included the working code I have that uses a text input field with a submit button - I want predetermined data to be saved to a sharedobject once the user clicks a Return to Menu button without having to enter any text. Hope someone can help. thanks



I have an input text field labeled "yourtext" and a submit button. The actionscript in the first line of the main.swf is:

if( init == null )

init = true;
so = SharedObject.getLocal( "one", "/");

//the "/" looks in the root area of Flash's shared object repository
//the course's "domain name" defines the root level for the
//shared object

if( (so.data.yourtext != null) )
{
//checks to see if "one" object has data in it,
yourtext = so.data.yourtext;
//gets data and displays in input box object
}


the submit button code:

on (press) {
loadMovie("main.swf", 0);


{
if( init == null )
init = true;

so = SharedObject.getLocal( "one", "/");

if( (yourtext != null) )
//checks if the input box contains data
{
so.data.yourtext = yourtext;
//gets input box variable content and updates shared object "one"
so.flush();
//sends new one input variable to the learner's local machine
}
}

}


In the receiving swf I have a dynamic text field labeled yourtext. The AS in the first frame is:

if( init == null )

init = true;
so = SharedObject.getLocal( "one", "/");

//if shared object has data already in it
if( (so.data.yourtext != null) )
{
//gets data and stores in text box object
yourtext = so.data.yourtext;

}
 
Your code...
Code:
 if( (yourtext != null) )
    //checks if the input box contains data
    {
        so.data.yourtext = yourtext;
        //gets input box variable content and updates shared object "one"
        so.flush();
        //sends new one input variable to the learner's local machine
    }
...would be...
Code:
so.data.yourtext = "Whatever";
so.flush();

Kenneth Kawamoto
 
kennethkawamoto -- that worked perfectly!! thanks!

Would it be possible to play a movieclip instead of or in addition to displaying text on the main movie.swf once the user clicks on the Return to Main button?

using something like this?? (using a MC with the first frame being blank)

if (so.data.yourtext != null) {_root.popup.gotoAndStop(2)
 
I tried variations of this but no success. I have a 2 frame MC (named and instance labeled popup) on the root timeline in the Main movie.

_root.popup.gotoAndStop(2);

any suggestions??


on (press) {
loadMovie("main.swf", 0);


{
if( init == null )
init = true;

so = SharedObject.getLocal( "one", "/");

if( (yourtext1 != null) )
//checks if the input box contains data
{
so.data.yourtext1 = "done";
_root.popup.gotoAndStop(2);

//gets input box variable content and updates shared object "one"
so.flush();

//sends new "one" input variable to the learner's local machine
}
}

}
 
I was able to get the movieclip to play once I put the code inside the main.swf. However, I don't think the sharedobject is being generated without using the input text field. I was hoping to not require the user to input text but generate the sharedobject when only they hit the submit button(without a text input field). Any suggestions on how this could create the SO without inputing text and generating it when they press the submit button?

on (press) {
loadMovie("main.swf", 0);


{
if( init == null )
init = true;

so = SharedObject.getLocal( "one", "/");

if( (yourtext != null) )
//checks if the input box contains data
{
so.data.yourtext = "Whatever";
//gets input box variable content and updates shared object "one"
so.flush();
//sends new one input variable to the learner's local machine
}
}

}

 
That did the trick! Thanks!

Now the main.swf displays the text and it plays the MC.
 
So this all works great locally and even when I upload to a server it works great but when I try it via http:// it no longer works. ugh... I've done some searching on the web but the only suggestion I found so far was to add _root.user. Have you come across http: issues with using SObjects?
 
I think the sol file is created ok but the main.swf is not reading it. The only thing I can think of this that playhead is moving from frame 1 to 2 too quickly for it to read/find the sol file. I have this code in frame 2, it just continues to go back and forth btwn frame 1 and 2. I tried adding more frames btwn frame 1 and 2 but it did not help.

// reinit the hit

if ( hitside == "on")
{
hitside = "off";
}

gotoAndPlay (1);
 
Still doesn't work. This is what i currently have:

code to read SO in main.swf:

if( init == null )

init = true;
so = SharedObject.getLocal( "one", "/");


{
//gets data and stores in text box object
yourtext1 = so.data.yourtext1;



}


submit button code in SO writing swf:

on (press) {
{
if( init == null )
init = true;

so = SharedObject.getLocal( "one", "/");


{
so.data.yourtext1 = "done";

so.flush();
loadMovie("main.swf", 0);

}
}

}

and code in frame one of same SO writing swf:

if( init == null )

init = true;
so = SharedObject.getLocal( "one", "/");


{

yourtext1 = so.data.yourtext1;

}
 
main.fla - TextField "yourtext1" is on Stage
Code:
//Main timeline
var so = SharedObject.getLocal("one", "/");
yourtext1.text = so.data.yourtext1;
stop();
base.fla - a Button is on Stage
Code:
//Button script
on (press) {
	var so = SharedObject.getLocal("one", "/");
	so.data.yourtext1 = "done";
	so.flush();
	loadMovie("main.swf", this);
}

Kenneth Kawamoto
 
Unfortunately this did not work. I appreciate your help though.


thanks
 
I think the reason that the latest code you added is not working for me is that I can't put that stop action in frame one of main.fla - the playhead for main.fla needs to constantly move from frame 1 to frame 2 and it won't read the SO and display it. That's the only thing I can think of. It works locally and when I click on the files directly in the network folder but when I play it in a browser it only displays the white dynamic box but no text inside the dynamic text field nor does it play the movieclip.

main.fla frame 1:
// variable init
hitside = "off";
speed = 8;

var so = SharedObject.getLocal("one", "/");
yourtext1.text = so.data.yourtext1;

xpos = getProperty(soldier, _x);
ypos = getProperty(soldier, _y);
xpos_right = getProperty(soldier, _x)+(getProperty(soldier, _width)/2);
xpos_left = getProperty(soldier, _x)-(getProperty(soldier, _width)/2);
xpos_top = getProperty(soldier, _y)-(getProperty(soldier, _height)/2);
xpos_bottom = getProperty(soldier, _y)+(getProperty(soldier, _height)/2);

// just for the ending animation

if (heli.hitTest(xpos_left, xpos_bottom, true)) {
soldier._visible = 0;
soldier._x = 0;
soldier._y = 0;
moveup = "true";
}

if (moveup == "true")
{
loadMovieNum ("screen1.swf", 0);

{
end = "true";
moveup = "false";
}
}

if (end == "true")
{
soldier._visible = 0
heli._visible = 0;

{
end = "false";
heli._visible = 0;
gotoAndStop(3);
}
}

// check for any hit on the side of the maze movie clip

if (maze.hitTest(xpos_right, xpos_bottom, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}

if (maze.hitTest(xpos_right, xpos_top, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}

if (maze.hitTest(xpos_left, xpos_bottom, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}

if (maze.hitTest(xpos_left, xpos_top, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}


// check for any hit on the side of the maze movie clip

if (maze.hitTest(xpos_right, xpos_bottom, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}

if (maze.hitTest(xpos_right, xpos_top, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}

if (maze.hitTest(xpos_left, xpos_bottom, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}

if (maze.hitTest(xpos_left, xpos_top, true)) {
hitside = "off";
} else {
hitside = "on";
soldier._x = oldx;
soldier._y = oldy;
}


// check for key press ...

if ((Key.isDown(Key.LEFT) && Key.isDown(Key.UP)) || (Key.isDown(Key.LEFT) && Key.isDown(Key.DOWN))) {
hitside = "on";
}

if ((Key.isDown(Key.RIGHT) && Key.isDown(Key.UP)) || (Key.isDown(Key.RIGHT) && Key.isDown(Key.DOWN))) {
hitside = "on";
}

if (!Key.isDown(Key.LEFT) && !Key.isDown(Key.RIGHT) && !Key.isDown(Key.UP) && !Key.isDown(Key.DOWN)) {
_root.soldier.man.stop();
} else {
_root.soldier.man.play();
}

if (Key.isDown(Key.LEFT) && hitside == "off") {
oldx = soldier._x;
oldy = soldier._y;
soldier._x -= speed;
_root.soldier.gotoAndStop("left");
}

if (Key.isDown(Key.RIGHT) && hitside == "off") {
oldx = soldier._x;
oldy = soldier._y;
soldier._x += speed;
_root.soldier.gotoAndStop("right");
}

if (Key.isDown(Key.UP) && hitside == "off") {
oldx = soldier._x;
oldy = soldier._y;
soldier._y -= speed;
_root.soldier.gotoAndStop("bottom");
}

if (Key.isDown(Key.DOWN) && hitside == "off") {
oldx = soldier._x;
oldy = soldier._y;
soldier._y += speed;
_root.soldier.gotoAndStop("top");
}




main.fla frame 2:
if ( hitside == "on")
{
hitside = "off";
}

gotoAndPlay (1);


main.fla frame 3:
stop();
 
Separate the code you want to run repeatedly and run once, then use [tt]onEnterFrame[/tt] or Interval for the repeating code. You can do everything in one Frame. Moving the play-head constantly between Frame 1 and 2 is Flash 4 and before approach, but if you want put run once script in Frame 1 and loop Frame 2 and 3.

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top