as3 slideshow won't load - actionscript-3

This problem has been driving me up the wall for months. I can't figure out why my background on my website:
www.the-ruck.us
Doesn't load properly.
I know the code works, because when I run it on my computer, everything loads fine. However, when I publish it to the web, and browse to my page, the slideshow just stays blank.
Here's the API for the XMLLoader class I use
Here's the code:
var slideshowXMLLoader:XMLLoader = new XMLLoader("slideshow.xml", {autoDispose:true, onComplete:LoadXML});
slideshowXMLLoader.load();
function LoadXML(e:Event) {
slideshowXML = new XML(e.target.content);
parse(slideshowXML);
}
function parse(ssXML:XML) { wallpaperLinks = slideshowXML.img.attributes(); }
function loadFirstPaper() {
ticker.addEventListener(TimerEvent.TIMER, changePaper);
TweenMax.to(landing, .5, {alpha:0, ease:Quint.easeOut});
TweenMax.to(bloomer, 1, {alpha:0, ease:Quint.easeOut});
loadWallpaper(randomNumber());
}
function loadWallpaper(i:Number) {
paperCounter = i;
var loader:Loader = new Loader();
var req:URLRequest = new URLRequest(wallpaperLinks[paperCounter]);
loader.load(req);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fadeIn);
}
function fadeIn(e:Event) {
if (!isPaused) ticker.start();
var temp = e.target.content;
wallpaper.addChild(temp);
TweenMax.from(temp, fadeTime, {alpha:0, ease:Quint.easeOut});
}
function changePaper(e:Event) {
ticker.stop();
loadWallpaper(randomNumber());
}
function randomNumber():Number
{ return Math.floor(Math.random() * 53); }
}
slideshow.xml contains this:
<wallpapers>
<img link="imgs/one.jpg"></img>
<img link="imgs/two.jpg"></img>
<img link="imgs/three.jpg"></img>
<img link="imgs/four.jpg"></img>
<img link="imgs/five.jpg"></img>
<img link="imgs/six.jpg"></img>
<img link="imgs/seven.jpg"></img>
<img link="imgs/eight.jpg"></img>
<img link="imgs/nine.jpg"></img>
<img link="imgs/ten.jpg"></img>
<img link="imgs/eleven.jpg"></img>
<img link="imgs/twelve.jpg"></img>
<img link="imgs/thirteen.jpg"></img>
<img link="imgs/fourteen.jpg"></img>
<img link="imgs/fifteen.jpg"></img>
<img link="imgs/sixteen.jpg"></img>
<img link="imgs/seventeen.jpg"></img>
<img link="imgs/eighteen.jpg"></img>
<img link="imgs/nineteen.jpg"></img>
<img link="imgs/twenty.jpg"></img>
<img link="imgs/twentyone.jpg"></img>
<img link="imgs/twentytwo.jpg"></img>
<img link="imgs/twentythree.jpg"></img>
<img link="imgs/twentyfour.jpg"></img>
<img link="imgs/twentyfive.jpg"></img>
<img link="imgs/twentysix.jpg"></img>
<img link="imgs/twentyseven.jpg"></img>
<img link="imgs/twentyeight.jpg"></img>
<img link="imgs/twentynine.jpg"></img>
<img link="imgs/thirty.jpg"></img>
<img link="imgs/thirtyone.jpg"></img>
<img link="imgs/thirtytwo.jpg"></img>
<img link="imgs/thirtythree.jpg"></img>
<img link="imgs/thirtyfour.jpg"></img>
<img link="imgs/thirtyfive.jpg"></img>
<img link="imgs/thirtysix.jpg"></img>
<img link="imgs/thirtyseven.jpg"></img>
<img link="imgs/thirtyeight.jpg"></img>
<img link="imgs/thirtynine.jpg"></img>
<img link="imgs/fourty.jpg"></img>
<img link="imgs/fourtyone.jpg"></img>
<img link="imgs/fourtytwo.jpg"></img>
<img link="imgs/fourtythree.jpg"></img>
<img link="imgs/fourtyfour.jpg"></img>
<img link="imgs/fourtyfive.jpg"></img>
<img link="imgs/fourtysix.jpg"></img>
<img link="imgs/fourtyseven.jpg"></img>
<img link="imgs/fourtyeight.jpg"></img>
<img link="imgs/fourtynine.jpg"></img>
<img link="imgs/fifty.jpg"></img>
<img link="imgs/fiftyone.jpg"></img>
<img link="imgs/fiftytwo.jpg"></img>
<img link="imgs/fiftythree.jpg"></img>
</wallpapers>
I've tried running Firebug on my site, and, unless I was doing that wrong, too, no errors or warnings came up. So I'm completely stumped. Anybody have any ideas?
Any help is deeply appreciated, thank you.

OK here is what I believe is happening. I went to your site and it throws a null reference error in loadWallpaper(). This only thing in loadWallpaper() that could be null that I can tell is wallpaperLinks. wallpaperLinks is set after the XMLLoader has completed it's load. You didn't show the code that calls loadFirstPaper(). So I bet you have a race condition. On your computer, the local load of the XML happens faster than online so you don't see it local.
Do this, move you loadFirstPaper call to here:
function parse(ssXML:XML) {
wallpaperLinks = slideshowXML.img.attributes();
loadFirstPaper();
}

Figured it out. The problem was
var slideshowXMLLoader:XMLLoader = new XMLLoader("slideshow.xml", {autoDispose:true, onComplete:LoadXML});
Either the XMLLoader wasn't doing it's job at all; or, and I think this is more likely, the onComplete event was firing prematurely. I replaced the above line with:
var slideshowXMLLoader:URLLoader = new URLLoader();
slideshowXMLLoader.addEventListener(Event.COMPLETE, loadXML);
slideshowXMLLoader.load(new URLRequest("slideshow.xml"));
It currently appears to be working as intended.
I would still like to know how to make onComplete calls work properly, so if anybody has any advice, I would love to hear it.
Thanks.

Related

Opening Video Thumbnail - video will open but will not load

For context, this is just a website that displays a thumbnail gallery linking to larger photos/videos.
When the thumbnails of photos are opened there is no problem. The thumbnails with a video attached to them look identical to the photo thumbnail only until the video thumbnail is clicked and the video will not load. Reference the HTML(first block) & javascript(second block) code below, any help would be greatly appreciated, this is my own personal project and I have been stuck for a couple days lol. if there any other information required, please do not hesitate to ask
This what happens when the thumbnail with the video is clicked but the video DOES NOT PLAY :(
<!-- code below is the PHOTO block of code ! -->
<article class="thumb">
<a href="images/fulls/21.jpg" class="image">
<img src="images/thumbs/21.jpg" class="image" alt="" /></a>
<h2> Cmon mayne</h2>
<p>Photoshoot with Myles Jay </p>
</article>
<!-- code below is the VIDEO block of code ! -->
<article class="thumb">
<a href="images/fulls/16.mp4" type="video/mp4" video
src="images/fulls/16.mp4" class="image">
<img src="images/thumbs/ab22.jpg" class="image" alt="" />
</a> <h2> Getting to the work</h2>
<p>Photoshoot with Myself </p>
</article>
// Main.
var $main = $('#main');
// Thumbs.
$main.children('.thumb').each(function() {
var $this = $(this),
$image = $this.find('.image'), $image_img = $image.children('img'),
x;
// No image? Bail.
if ($image.length == 0)
return;
// Image.
// This sets the background of the "image" <span> to the image pointed to by its child
// <img> (which is then hidden). Gives us way more flexibility.
// Set background.
$image.css('background-image', 'url(' + $image_img.attr('src') + ')');
// Set background position.
if (x = $image_img.data('position'))
$image.css('background-position', x);
// Hide original img.
$image_img.hide(); });
// Poptrox.
$main.poptrox({
baseZIndex: 20000,
caption: function($a) {
var s = '';
$a.nextAll().each(function() {
s += this.outerHTML;
});
return s;
},
fadeSpeed: 300,
onPopupClose: function() { $body.removeClass('modal-active'); },
onPopupOpen: function() { $body.addClass('modal-active'); },
overlayOpacity: 0,
popupCloserText: '',
popupHeight: 150,
popupLoaderText: '',
popupSpeed: 300,
popupWidth: 150,
selector: '.thumb > a.image',
usePopupCaption: true,
usePopupCloser: true,
usePopupDefaultStyling: false,
usePopupForceClose: true,
usePopupLoader: true,
usePopupNav: true,
windowMargin: 50
});
// Hack: Set margins to 0 when 'xsmall' activates.
breakpoints.on('<=xsmall', function() {
$main[0]._poptrox.windowMargin = 0;
});
breakpoints.on('>xsmall', function() {
$main[0]._poptrox.windowMargin = 50;
});
})(jQuery);
I have searched every stackoverflow method mentioning a thumbnail and video, I am honestly stuck. I have been playing around with the tags and attributes but I have seem to be getting no where.
Try setting up your <article> as:
<article class="thumb">
<a href="images/fulls/16.mp4">
<img src="images/thumbs/ab22.jpg" class="image" alt="" />
</a> <h2> Getting to the work</h2>
<p>Photoshoot with Myself </p>
</article>

State in React component not setting data when the browser (tab) is refreshed

I have this simple react component that gets data from an API (fetch called in UseEffect), and displays it using HTML. When I refresh the page, all html disappears from the page and it goes blank. What's peculiar is that when I instead make some changes in the code editor and let react autoupdate the page after saving, it displays everything just fine.
Here's the code snippet for the component:
export function AgentCard(props){
console.log("agentcard function");
const [agentData,setAgentData] = useState({});
useEffect(()=> {
console.log('running useEffect')
axios.get('https://valorant-api.com/v1/agents/').then(res=>{
var agentRes;
for (const agent of res.data['data']){
if (agent['displayName'] === props.agentName){ agentRes = agent}
}
setAgentData(agentRes);
console.log(agentData)
})
},[])
return(
<div className='AgentCard'>
<h2>{agentData['displayName']}</h2>
<img src={agentData['displayIcon']}></img>
<div className='AgentCardBody'>
<div className='AbilitiesBar'>
<img src={agentData['abilities'][0]['displayIcon']} className='AbilitiesIcon'></img>
<img src={agentData['abilities'][1]['displayIcon']} className='AbilitiesIcon'></img>
<img src={agentData['abilities'][2]['displayIcon']} className='AbilitiesIcon'></img>
<img src={agentData['abilities'][3]['displayIcon']} className='AbilitiesIcon'></img>
</div>
</div>
</div>
)
After some digging and logging, what I found is that when I refresh the page, the state (agentData), is saved to this:
https://imgur.com/a/QzfIdpm
and get the following error in the console:
https://imgur.com/a/H7gLiTQ
But once I make any change to the editor and let react autorefresh, the logs show that the state agentData has the right data object pulled from the API.
Also, this only happens when I have the following part of the code running
<img src={agentData['abilities'][0]['displayIcon']} className='AbilitiesIcon'></img>
<img src={agentData['abilities'][1]['displayIcon']} className='AbilitiesIcon'></img>
<img src={agentData['abilities'][2]['displayIcon']} className='AbilitiesIcon'></img>
<img src={agentData['abilities'][3]['displayIcon']} className='AbilitiesIcon'></img>
Once I comment this out, everything displays correctly even after a browser refresh
I know the way I've posed the question is confusing, but I'm new to front end development and don't really know what I'm supposed to look for here.
Probably because agentData.abilities returns undefined (remember that you have an empty object that is asynchronously populated), but you're trying to access it in your template as if an array is present.
You can solve this easily if you conditionally render those <img> elements when agentData.abilities is not undefined, i.e.:
return(
<div className='AgentCard'>
<h2>{agentData['displayName']}</h2>
<img src={agentData['displayIcon']}></img>
<div className='AgentCardBody'>
{agentData.abilities && (
<div className='AbilitiesBar'>
<img src={agentData.abilities[0].displayIcon} className='AbilitiesIcon' />
<img src={agentData.abilities[1].displayIcon} className='AbilitiesIcon' />
<img src={agentData.abilities[2].displayIcon} className='AbilitiesIcon' />
<img src={agentData.abilities[3].displayIcon} className='AbilitiesIcon' />
</div>
)}
</div>
</div>
)
Even better: you can simply iterate through the first 4 entries in agentData.abilities to keep your DOM a bit simpler:
return(
<div className='AgentCard'>
<h2>{agentData['displayName']}</h2>
<img src={agentData['displayIcon']}></img>
<div className='AgentCardBody'>
<div className='AbilitiesBar'>
{agentData.abilities && agentData.abilities.slice(0,4).forEach(ability => (
<img src={ability.displayIcon} className='AbilitiesIcon' />
)}
</div>
</div>
</div>
)

how to remove title in img html

i have a html text like that i get from database, but it have a hover that show the image name, so i want to remove the title
from this
<img title="AAAAAAA" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" alt="" width="212" height="212">
to this
<img title="" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" alt="" width="212" height="212">
i have tried
var text = '<img title="AAAAAAA" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" alt="" width="212" height="212">'
text.replace(/(<img .*title=")(.+)(")/, '$1$3')
but it also remove my src
"<img title="">"
any help guys ?
You could use JS function removeAttribute():
document.getElementById("someId").removeAttribute("title");
console.log(document.getElementById("someId"));
<img title="AAAAAAA" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" alt="" width="212" height="212" id="someId">
EDIT: How to remove with regex
var text = '<img title="AAAAAAA" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" alt="" width="212" height="212">';
console.log(text.replace(/ title=".[^"]*"/, ''))
How to remove only titleĀ“s value:
var text = '<img title="AAAAAAA" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" alt="" width="212" height="212">';
console.log(text.replace(/title=".[^"]*"/, 'title=""'))
If you are only getting the element as a string and not as a DOM element, then you can try using \"[\s\S]+(?= ) to select the portion of string that goes from the first " to the first space (returning you "AAAAAAA").
You can then replace the text as per your code in the question.
It can be very hard, if not impossible, to reliably parse HTML using the likes of regex, indexOf, etc. The whole issue can be totally avoided by using the built-in DOMParser object, as follows:
const html = '<img title="AAAAAAA" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" alt="" width="212" height="212">';
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
const img = doc.body.children[0];
img.title = "";
console.log(img.outerHTML)
You could also use img.removeAttribute("title"); if you want to get totally rid of the title attribute.
Simpler and cleaner way.
var xmlString = '<img title="AAAAAAA" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885_960_720.jpg" alt="" width="212" height="212">'
var x = new DOMParser().parseFromString(xmlString, "text/xml").documentElement
x.removeAttribute("title")
console.log(x)

CSS how to use onclick and this to bind to a different element

Ok, I'll try to explain as best I can.
Here is my code:
HTML:
<div class="mobile-wrapper">
<div id="mobile" class="mobile">
<img src="assets/images/mobile-moments-away-img.png">
<img id="mobile-close-btn" class="mobile-close-btn" src="assets/images/mobile-close-button-img.png" onclick="handleClose(this)">
<img id="mobile-continue-btn" class="mobile-continue-btn" src="assets/images/mobile-continue-now-img.png">
</div>
</div>
JS:
const handleClose = (elem) => {
console.log(elem);
elem.style.display = "none";
};
So, currently the handclose function currently hides the element, in this case it closes the image that has onclick="handleClose(this). What I need, is that when I click that image, it closes the mobile class instead of closing that image. So I am unsure how to reference the mobile class whilst still using this.
I have to use this as I have been asked too. Because I have the same HTML as above but for different images, as the JavaScript functions will doing the same thing for the above HTML as well as the different images I have. For example: My handleclose function will be using different elements but doing the same thing, hence why I am using this. So I would appreciate some help with this, and not to be told to do it a different way ie getelementbyid as that's not what I need.
Also, how would I be able to use elem.parentElement in this function, where popUp should be elem.parentElement
document.addEventListener("visibilitychange", () => {
if (!cookieExists()) {
popUp.style.visibility = "visible";
// popUp.style.top = "10vh";
document.cookie = `${cookieName}=true;max-age=604800;SameSite=None; Secure`;
}
});
You can refer to the parent element using .parentElement:
const handleClose = (elem) => {
elem.parentElement.style.display = "none";
};
<div class="mobile-wrapper">
<div id="mobile" class="mobile">
<img src="assets/images/mobile-moments-away-img.png">
<img id="mobile-close-btn" class="mobile-close-btn" src="assets/images/mobile-close-button-img.png" onclick="handleClose(this)">
<img id="mobile-continue-btn" class="mobile-continue-btn" src="assets/images/mobile-continue-now-img.png">
</div>
<div id="mobile" class="mobile">
<img src="assets/images/mobile-moments-away-img.png">
<img id="mobile-close-btn" class="mobile-close-btn" src="assets/images/mobile-close-button-img.png" onclick="handleClose(this)">
<img id="mobile-continue-btn" class="mobile-continue-btn" src="assets/images/mobile-continue-now-img.png">
</div>
<div id="mobile" class="mobile">
<img src="assets/images/mobile-moments-away-img.png">
<img id="mobile-close-btn" class="mobile-close-btn" src="assets/images/mobile-close-button-img.png" onclick="handleClose(this)">
<img id="mobile-continue-btn" class="mobile-continue-btn" src="assets/images/mobile-continue-now-img.png">
</div>
</div>

Getting an image to my html from my controller in angular.js

I cant seem to get the image to show up. How exactly would I write this to get it in my html from my controller using angular.js? I am using a ui-router also
The title shows up, but not the image.
Controller:
angular
.module('app')
.controller('aboutCtrl', ['$scope', function($scope){
$scope.title = "About",
$scope.image = "images/myimage.jpg";
}]);
HTML:
<h3 class="center">{{title}}</h3>
<figure class="image">
<img ng-src="{{image}}" >
</figure>
I think you haven't passed reference of controller. try this.
<div ng-app="app" ng-controller="aboutCtrl">
<h3 class="center">{{title}}</h3>
<figure class="image">
<img ng-src="{{image}}" >
</figure>
<div>