/    Sign up×
Community /Pin to ProfileBookmark

can i put vars and expressions into an array?

hello – i have this code (and other variants) which i need to put into an array but i can’t figure out how:

var so = new SWFObject(“../lasdunashibiscos/dunas3.swf”, “las dunas”, “468”, “60”, “9”, “#ffffff”);
so.useExpressInstall(‘../2007flashes/expressinstall.swf’);
so.write(“flashcontent”);

I need it in this kind of manner but this of course doesn’t work:

contents[0]= ‘var so = new SWFObject(“../lasdunashibiscos/dunas3.swf”, “las dunas”, “468”, “60”, “9”, “#ffffff”); so.useExpressInstall (“../2007flashes/expressinstall.swf”); so.write(“flashcontent”)’;

Any help will be much appreciated.

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@jsakalosJun 12.2007 — You are putting [I]string[/I] with code into the array. If you want to run it the eval should help you.

[code=php]

eval(contents[0]);

[/code]
Copy linkTweet thisAlerts:
@webewitchauthorJun 12.2007 — sorry but I can't get that to work either - tried this both with and without the obliques before the semicolons but doesn't work:

eval (contents[3]); var so2 = new SWFObject("../uktv/z132.swf", "goldacre", "468", "60", "9", "#ffffff"); so2.useExpressInstall ("../2007flashes/expressinstall.swf"); so2.write("flashcontent2");

Am I doing it all wrong?
Copy linkTweet thisAlerts:
@toicontienJun 12.2007 — var so = [];
so.push(new SWFObject("../lasdunashibiscos/dunas3.swf", "las dunas", "468", "60", "9", "#ffffff"));
so[0].useExpressInstall('../2007flashes/expressinstall.swf');
so[0].write("flashcontent");
Copy linkTweet thisAlerts:
@jsakalosJun 12.2007 — sorry but I can't get that to work either - tried this both with and without the obliques before the semicolons but doesn't work:

eval (contents[3]); var so2 = new SWFObject("../uktv/z132.swf", "goldacre", "468", "60", "9", "#ffffff"); so2.useExpressInstall ("../2007flashes/expressinstall.swf"); so2.write("flashcontent2");

Am I doing it all wrong?[/quote]

Let's make it simplest possible. Try to run this code:

[code=php]

var contents = new Array();
contents.push('alert("Hello World");');
eval(contents[0]);

[/code]

Got the idea?
Copy linkTweet thisAlerts:
@toicontienJun 12.2007 — Using eval in this instance is like hitting a thumbtack with a hammer. All you need is an array. The code I posted will work just fine. No need to make a copy of the window object and fire up eval() for this.
Copy linkTweet thisAlerts:
@jsakalosJun 12.2007 — He is writing he wants to put [B]code[/B] into the array. I don't what for but I answered exactly his question.

Your code works for sure putting [B]object[/B] into array. So let him choose what he really needs in the context of his application.

I'm also trying to avoid eval as much as possible. ?
Copy linkTweet thisAlerts:
@webewitchauthorJun 12.2007 — sorry guys and thank you both for trying to help me - i hadn't ecplained myself clearly.

I'll have several flashes in this format :

<script language="javascript" type="text/javascript">

var so = new SWFObject("../lasdunashibiscos/dunas3.swf", "las dunas", "468", "60", "9", "#ffffff");

so.useExpressInstall('../2007flashes/expressinstall.swf');

so.write("flashcontent");

var so1= new SWFObject("../lasdunashibiscos/dunas2.swf", "las dunas2", "468", "60", "9", "#ffffff");
so1.useExpressInstall('../2007flashes/expressinstall.swf');
so1.write("flashcontent1");

</script>

etc etc.

...and I have a code that will put them in random order based on the array contents[0] etc.

var contents=new Array()

contents[0]=

etc - I've been using this with gifs and jpgs and it works fine - so I was hoping to be able to put the arrays with the above two examples (and more) in in place of the gifs. I apologise for testing your patience again.
Copy linkTweet thisAlerts:
@JMRKERJun 12.2007 — Pretty neat sledge hammer for such a small tack! :eek:
[code=php]
<html>
<head
<title>Eval Test</title>
<style type="text/css">
li.nav {
font: 1em "Comic Sans MS",cursive;
}
</style>
<script type="text/javascript">
var Cmmds = new Array();
Cmmds[0] = 'alert("Hello World")';
Cmmds[1] = 'window.location="http://optometry.nova.edu"'
Cmmds[2] = 'window.location="http://www.webdeveloper.com"';
Cmmds[3] = 'window.location="http://www.google.com"';
Cmmds[4] = 'window.location="http://www.javascripts.com"';
Cmmds[5] = 'window.location="http://www.nova.edu"';
Cmmds[6] = 'document.getElementById("imgbox").src="http://www.nova.edu/images/NSULogoBlueMed.gif"';
Cmmds[7] = 'document.getElementById("imgbox").src="http://www.nova.edu/common-lib/images/nsu_b_57.jpg"';
Cmmds[8] = 'document.getElementById("comment").innerHTML=Comments';
Cmmds[9] = 'window.location="http://www.cssbasics.com"';

var Comments = '<font color=magenta><h1>WOW!</h1></font>';
Comments += '<p />Pretty neat hammer for such a small tack!';

function EvalCmmd(Cmmd) {
eval(Cmmds[Cmmd]);
}
</script>
</head>
<body>
<button onClick="EvalCmmd(0)">Test Alert</button>
<button onClick="EvalCmmd(1)">Test Link</button>
<a href='javascript:void(0)' onClick="EvalCmmd(9)">Test Anchor to cssbasics.com</a>
<p />
<button onClick="EvalCmmd(6)">Test Image 1</button>
<button onClick="EvalCmmd(7)">Test Image 2</button>
<br />
<img id="imgbox" src='' alt="Image Goes Here" />
<p />
<div style='width: 150px;'>
Menu test
<li onClick="EvalCmmd(2)"
onMouseOver="style.color='red';style.backgroundColor='yellow'"
onMouseOut="style.color='black';style.backgroundColor='transparent'">Webdeveloper</li>
<li onClick="EvalCmmd(3)"
onMouseOver="style.color='red';style.backgroundColor='yellow'"
onMouseOut="style.color='black';style.backgroundColor='transparent'">Google</li>
<li onClick="EvalCmmd(4)"
onMouseOver="style.color='red';style.backgroundColor='yellow'"
onMouseOut="style.color='black';style.backgroundColor='transparent'">Javascripts.com</li>
<li onClick="EvalCmmd(5)"
onMouseOver="style.color='red';style.backgroundColor='yellow'"
onMouseOut="style.color='black';style.backgroundColor='transparent'">University</li>
</div>
<br />
<button onClick="EvalCmmd(8)">Test innerHTML</button>
<span id="comment"></span>
<hr>
</body>
</html>
[/code]
Copy linkTweet thisAlerts:
@webewitchauthorJun 13.2007 — Guys - thank you so much!

I finally figured it out thanks to your help.

I am a happy chappie now.

I really do appreciate the time and effort you put in for totally altruistic motives.

Thanks again.
×

Success!

Help @webewitch spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...