# Create Array from dynamic vars

**URL:** <https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769>\
**Category:** flash\
**Created:** [April 24, 2006, 2:47pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769 "2006-04-24T14:47:04Z")\
**Posts on this page:** 16\
**Page:** 2

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 24, 2006, 9:02pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/21 "2006-04-24T21:02:07Z")

</div>

```auto
var myVars:LoadVars = new LoadVars();
myVars.sendAndLoad("flash.php", myVars, "POST");
myVars.onLoad = function(){
   trace(myVars.totalr);
}

```

That should work as long as the php is working and they are in the same folder

BTW:

> I even set the php to just echo “totalr=3”

with quotes or without?

---

<div class="post-metadata">

**Author:** ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)\
**Post date:** [April 24, 2006, 9:19pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/22 "2006-04-24T21:19:28Z")

</div>

Like defective said, they’re are definitely more robust / effecient ways of doing this, especially if your gallery contains hundreds of images. However, if you change the echo string in your php to this - I’m just eliminating the double quotes from the string passed from php:

```auto

echo 'pic'.$x.'=gallery/'.$pic.',gallery/'.$thumb.'&';

```

then you can use the following to formulate the array, if this is a small gallery and this works, I’d say use it if you’re in a rush. But it will be worthwhile to build on / edit this if you want this to be something thats really efficient and reusable (that pretty much goes without saying I guess when questions are answered on these forums 😏 )

[AS]  
var objArray:Array = [];

var loadV:LoadVars = new LoadVars();  
loadV.onLoad = function() {  
for(var i in this) {  
//a quick filter to grab all props of the loadVars that aren’t built-in methods  
if(i.substr(0,3)==“pic”) {  
var tempArray:Array = this\*.split(",");  
var tempObject:Object = {img:tempArray[0],thumb:tempArray[1]};  
objArray.push(tempObject);  
}  
}

```
// this will trace all the objects, you can delete this later:
var len:Number = objArray.length;
for(var j:Number=0; j&lt;len; j++) {
	trace(objArray[j]+" = "+objArray[j].img+ " & "+objArray[j].thumb);
}
// you'd place your 
// mygallery.createFromArray(objArray);
// call here - asl long as all of this code is on frame in the main timeline vs. an AS2 Class

```

}

var phppath:String = “pathtoyourphpfile.php”;  
loadV.load(phppath);  
[/AS]

---

<div class="post-metadata">

**Author:** ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)\
**Post date:** [April 24, 2006, 9:23pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/23 "2006-04-24T21:23:12Z")

</div>

shoot guys - sorry - I didn’t see all of the work on page two of this thread, hope it all worked out!

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 24, 2006, 9:31pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/24 "2006-04-24T21:31:43Z")

</div>

cr --\> dude ill try your solutions also man…thansk again so much  
def --\> so the output look like totalr=3

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 24, 2006, 9:54pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/25 "2006-04-24T21:54:09Z")

</div>

Creat --\> ive gotten furtehr with your method at the moment man …the gallery actually gets closer to loading buthis is shown in the out put window:

[object Object] = gallery/’.$pic.’ & undefined  
Loading ERROR CODE = URLNotFound  
Unable to connect to URL: file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/’.$pic.‘  
Error opening URL "file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/’.$pic.’"

Seems like somehow the php is gettin sucked into flash …but all that displays in a browser window is the string?!

---

<div class="post-metadata">

**Author:** ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)\
**Post date:** [April 24, 2006, 9:55pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/26 "2006-04-24T21:55:54Z")

</div>

this is in the path to your php doc?  
The%20Phoenix%20Rose%20Admin/gallery/

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 24, 2006, 10:00pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/27 "2006-04-24T22:00:36Z")

</div>

path to php doc: localhost/the phoenix rose admin/ (php doc and flash here)  
path to images:localhost/the phoenix rose admin/gallery

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 24, 2006, 10:02pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/28 "2006-04-24T22:02:12Z")

</div>

Loading ERROR CODE = URLNotFound  
Unable to connect to URL: file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/’.$pic.‘  
Error opening URL "file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/’.$pic.’"

PS suspect those errors are out put from the component!

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 24, 2006, 10:20pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/29 "2006-04-24T22:20:54Z")

</div>

This is the output when i try moving the ampersand to the START of the string:

[object Object] = gallery/’.$pic.’ & gallery/’.$thumb;

$x ;

}

?\>  
Error opening URL "file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/’.$thumb;

$x ;

}

?\> “  
Loading ERROR CODE = URLNotFound  
Unable to connect to URL: file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/’.$pic.‘  
Error opening URL "file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/’.$pic.’”

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 24, 2006, 10:24pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/30 "2006-04-24T22:24:34Z")

</div>

Hope this isnt annoying but here’s something else ive tried on the php side:

```php

&lt;?

include ('functions.php');
$sql= "SELECT * FROM gallery";
$query = mysql_query($sql);
$total = mysql_num_rows($query);
$x=1;
$string = "&";
while ($result = mysql_fetch_array($query)){
$pic = $result['picture'];
$thumb= $result['thumbnail'];
$string .= 'pic'.$x.'=gallery/'.$pic.',gallery/'.$thumb;
$x++;
}
$string .= "&";
echo $string;
?&gt; 
[/]php]
This results in no visible out put at all!
```

---

<div class="post-metadata">

**Author:** ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)\
**Post date:** [April 24, 2006, 10:28pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/31 "2006-04-24T22:28:01Z")

</div>

we’ve all been there, trying to get a project done and nothing but error after error, its frustrating

yeah, it seems to me that the php isn’t working right - I just don’t know enough about php to be much help. The errors seem to show that the php isn’t returning the proper names of the images - I’m guessing all your images are non-progressive jpgs?

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 24, 2006, 10:31pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/32 "2006-04-24T22:31:50Z")

</div>

conclusion: sumthing to do with the / behind gallery …ithink?

But I got no idea how to deal with it!

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 24, 2006, 10:32pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/33 "2006-04-24T22:32:51Z")

</div>

sorry bro didnt see your reply …yeah i dont think its a problem with the images. When i use the outputed string in a static file tha gallery works a charm!

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 24, 2006, 10:36pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/34 "2006-04-24T22:36:20Z")

</div>

defec --\> any clue what could be goin on PHP side her man?

even odder:

```php

<?
/*
include ('../Connections/tpr.php');
$sql= "SELECT * FROM gallery";
$query = mysql_query($sql);
$total = mysql_num_rows($query);
$x=1;

while ($result = mysql_fetch_array($query)){
$pic = $result['picture'];
$thumb= $result['thumbnail'];
echo "&pic".$x."=gallery/".$pic.",gallery/".$thumb;
$x++;
}
*/

echo "&pic1=Sunset.jpg,tSunset.jpg&pic2=Winter.jpg,tWinter.jpg&pic3=Sunset.jpg,tSunset.jpg";
?> 

```

Even with the code commented out …and on the plain var string put out i get these errors:

```auto

[object Object] = Sunset.jpg & tSunset.jpg";

?> 
[object Object] = Winter.jpg & tWinter.jpg
[object Object] = Sunset.jpg & tSunset.jpg
[object Object] = gallery/".$pic." & gallery/".$thumb;

$x ;

}

*/

echo "
Error opening URL "file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/tSunset.jpg";

?> "
Error opening URL "file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/gallery/".$thumb;

$x ;

}

*/

echo ""

```

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 24, 2006, 10:48pm UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/35 "2006-04-24T22:48:54Z")

</div>

crit -\> dude i think this may have something to do with the way your spliting the string is your code.

when i change this\*.split(","); to this\*.split("&");

there are still errors but they look closer to the mark:

```auto

[object Object] = Sunset.jpg,tSunset.jpg";

?&gt; & undefined
[object Object] = Winter.jpg,tWinter.jpg & undefined
[object Object] = Sunset.jpg,tSunset.jpg & undefined
[object Object] = gallery/".$pic.",gallery/".$thumb;

$x ;

}

*/

echo " & undefined
Loading ERROR CODE = URLNotFound
Unable to connect to URL: file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/Sunset.jpg,tSunset.jpg";

?&gt; 
Error opening URL "file:///E|/EasyPHP1%2D8/www/The%20Phoenix%20Rose%20Admin/gallery/Sunset.jpg,tSunset.jpg";

?&gt; "
[/as&gt;

based on this output string:
&pic1=Sunset.jpg,tSunset.jpg&pic2=Winter.jpg,tWinter.jpg&pic3=Sunset.jpg,tSunset.jpg
```

---

<div class="post-metadata">

**Author:** ![Zaid\_W1red](https://avatars.discourse-cdn.com/v4/letter/z/cab0a1/32.png) [@Zaid\_W1red](https://forum.kirupa.com/u/Zaid_W1red)\
**Post date:** [April 25, 2006, 12:35am UTC](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769/36 "2006-04-25T00:35:13Z")

</div>

Well,  
I fixed my problem by setting my CMS to simply write the xml file using fopen when a picture is uploaded…so wish id done this earlier!

[Previous page](https://forum.kirupa.com/t/create-array-from-dynamic-vars/186769.md?page=1)
